diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-30 11:22:47 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 09dc160da98a0a4fe976d3d174cc93af57c53892 (patch) | |
tree | 07e19bbcb51bfab6ebfa5c5af1248a7dac901f14 /pkg | |
parent | e187293456ed8d66fd9582def7c8189312b98b35 (diff) |
cleaning up
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/branches_panel.go | 9 | ||||
-rw-r--r-- | pkg/gui/context/list_context_trait.go | 16 | ||||
-rw-r--r-- | pkg/gui/context/tags_context.go | 27 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 4 | ||||
-rw-r--r-- | pkg/gui/list_context.go | 10 | ||||
-rw-r--r-- | pkg/gui/remote_branches_panel.go | 9 | ||||
-rw-r--r-- | pkg/gui/sub_commits_panel.go | 9 | ||||
-rw-r--r-- | pkg/gui/types/context.go | 4 |
8 files changed, 34 insertions, 54 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index e524ef9a2..fa60b5ed7 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -445,3 +445,12 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error { func sanitizedBranchName(input string) string { return strings.Replace(input, " ", "-", -1) } + +func (gui *Gui) handleEnterBranch() error { + branch := gui.getSelectedBranch() + if branch == nil { + return nil + } + + return gui.switchToSubCommitsContext(branch.RefName()) +} diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index 776056fad..390059b2e 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -9,14 +9,8 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" ) -type Thing interface { - // the boolean here tells us whether the item is nil. This is needed because you can't work it out on the calling end once the pointer is wrapped in an interface (unless you want to use reflection) - GetSelectedItem() (types.ListItem, bool) -} - type ListContextTrait struct { base types.IBaseContext - thing Thing listTrait *ListTrait viewTrait *ViewTrait @@ -55,16 +49,6 @@ func formatListFooter(selectedLineIdx int, length int) string { return fmt.Sprintf("%d of %d", selectedLineIdx+1, length) } -func (self *ListContextTrait) GetSelectedItemId() string { - item, ok := self.thing.GetSelectedItem() - - if !ok { - return "" - } - - return item.ID() -} - // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view func (self *ListContextTrait) HandleRender() error { if self.GetDisplayStrings != nil { diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index f5e7f6cb8..5c2592cf9 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -7,7 +7,7 @@ import ( ) type TagsContext struct { - *TagsContextAux + *TagsList *BaseContext *ListContextTrait } @@ -35,12 +35,11 @@ func NewTagsContext( self := &TagsContext{} takeFocus := func() error { return c.PushContext(self) } - aux := NewTagsContextAux(getModel) + list := NewTagsList(getModel) viewTrait := NewViewTrait(getView) listContextTrait := &ListContextTrait{ base: baseContext, - thing: aux, - listTrait: aux.list, + listTrait: list.ListTrait, viewTrait: viewTrait, GetDisplayStrings: getDisplayStrings, @@ -57,39 +56,39 @@ func NewTagsContext( self.BaseContext = baseContext self.ListContextTrait = listContextTrait - self.TagsContextAux = aux + self.TagsList = list return self } -type TagsContextAux struct { - list *ListTrait +type TagsList struct { + *ListTrait getModel func() []*models.Tag } -func (self *TagsContextAux) GetItemsLength() int { +func (self *TagsList) GetItemsLength() int { return len(self.getModel()) } -func (self *TagsContextAux) GetSelectedTag() *models.Tag { +func (self *TagsList) GetSelectedTag() *models.Tag { if self.GetItemsLength() == 0 { return nil } - return self.getModel()[self.list.GetSelectedLineIdx()] + return self.getModel()[self.GetSelectedLineIdx()] } -func (self *TagsContextAux) GetSelectedItem() (types.ListItem, bool) { +func (self *TagsList) GetSelectedItem() (types.ListItem, bool) { tag := self.GetSelectedTag() return tag, tag != nil } -func NewTagsContextAux(getModel func() []*models.Tag) *TagsContextAux { - self := &TagsContextAux{ +func NewTagsList(getModel func() []*models.Tag) *TagsList { + self := &TagsList{ getModel: getModel, } - self.list = &ListTrait{ + self.ListTrait = &ListTrait{ selectedIdx: 0, HasLength: self, } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index f2d44690c..4d8eddb48 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -488,7 +488,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding { ViewName: "branches", Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: gui.getKey(config.Universal.GoInto), - Handler: gui.handleSwitchToSubCommits, + Handler: gui.handleEnterBranch, Description: gui.c.Tr.LcViewCommits, }, { @@ -510,7 +510,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding { ViewName: "branches", Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, Key: gui.getKey(config.Universal.GoInto), - Handler: gui.handleSwitchToSubCommits, + Handler: gui.handleEnterRemoteBranch, Description: gui.c.Tr.LcViewCommits, }, { diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 6841dc569..fbdf78c50 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -60,16 +60,6 @@ func (self *ListContext) GetSelectedItem() (types.ListItem, bool) { return self.SelectedItem() } -func (self *ListContext) GetSelectedItemId() string { - item, ok := self.GetSelectedItem() - - if !ok { - return "" - } - - return item.ID() -} - // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view func (self *ListContext) HandleRender() error { view, err := self.Gui.g.View(self.ViewName) diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 5f60a4211..4164662ba 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -109,3 +109,12 @@ func (gui *Gui) handleCreateResetToRemoteBranchMenu() error { return gui.helpers.refs.CreateGitResetMenu(selectedBranch.FullName()) } + +func (gui *Gui) handleEnterRemoteBranch() error { + selectedBranch := gui.getSelectedRemoteBranch() + if selectedBranch == nil { + return nil + } + + return gui.switchToSubCommitsContext(selectedBranch.RefName()) +} diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go index 9f3eea642..a6fae60c9 100644 --- a/pkg/gui/sub_commits_panel.go +++ b/pkg/gui/sub_commits_panel.go @@ -102,12 +102,3 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error { return gui.c.PushContext(gui.State.Contexts.SubCommits) } - -func (gui *Gui) handleSwitchToSubCommits() error { - currentContext := gui.currentSideListContext() - if currentContext == nil { - return nil - } - - return gui.switchToSubCommitsContext(currentContext.GetSelectedItemId()) -} diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index eadcf41ad..48e3cfdba 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -62,21 +62,19 @@ type IController interface { type IListContext interface { HasKeybindings GetSelectedItem() (ListItem, bool) - GetSelectedItemId() string HandlePrevLine() error HandleNextLine() error HandleScrollLeft() error HandleScrollRight() error + HandlePrevPage() error HandleNextPage() error HandleGotoTop() error HandleGotoBottom() error - HandlePrevPage() error HandleClick(onClick func() error) error OnSearchSelect(selectedLineIdx int) error FocusLine() - HandleRenderToMain() error GetPanelState() IListPanelState |