diff --git a/pkg/commands/branch.go b/pkg/commands/branch.go index 27ac548a8..b182b8b6d 100644 --- a/pkg/commands/branch.go +++ b/pkg/commands/branch.go @@ -16,3 +16,7 @@ type Branch struct { func (b *Branch) RefName() string { return b.Name } + +func (b *Branch) ID() string { + return b.RefName() +} diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go index 1058e8ec6..c0483f3f0 100644 --- a/pkg/commands/commit.go +++ b/pkg/commands/commit.go @@ -28,3 +28,7 @@ func (c *Commit) NameWithSha() string { func (c *Commit) RefName() string { return c.Sha } + +func (c *Commit) ID() string { + return c.RefName() +} diff --git a/pkg/commands/commit_file.go b/pkg/commands/commit_file.go index a2cf6eb20..2b231e079 100644 --- a/pkg/commands/commit_file.go +++ b/pkg/commands/commit_file.go @@ -7,3 +7,7 @@ type CommitFile struct { DisplayString string Status int // one of 'WHOLE' 'PART' 'NONE' } + +func (f *CommitFile) ID() string { + return f.Name +} diff --git a/pkg/commands/remote.go b/pkg/commands/remote.go index 264e6a2c4..17ed8c1ca 100644 --- a/pkg/commands/remote.go +++ b/pkg/commands/remote.go @@ -10,3 +10,7 @@ type Remote struct { func (r *Remote) RefName() string { return r.Name } + +func (r *Remote) ID() string { + return r.RefName() +} diff --git a/pkg/commands/remote_branch.go b/pkg/commands/remote_branch.go index 0c7352d06..656546815 100644 --- a/pkg/commands/remote_branch.go +++ b/pkg/commands/remote_branch.go @@ -13,3 +13,7 @@ func (r *RemoteBranch) FullName() string { func (r *RemoteBranch) RefName() string { return r.FullName() } + +func (r *RemoteBranch) ID() string { + return r.RefName() +} diff --git a/pkg/commands/stash_entry.go b/pkg/commands/stash_entry.go index eb70693ef..487da0f00 100644 --- a/pkg/commands/stash_entry.go +++ b/pkg/commands/stash_entry.go @@ -11,3 +11,7 @@ type StashEntry struct { func (s *StashEntry) RefName() string { return fmt.Sprintf("stash@{%d}", s.Index) } + +func (s *StashEntry) ID() string { + return s.RefName() +} diff --git a/pkg/commands/tag.go b/pkg/commands/tag.go index 71a250c40..2009472b2 100644 --- a/pkg/commands/tag.go +++ b/pkg/commands/tag.go @@ -8,3 +8,7 @@ type Tag struct { func (t *Tag) RefName() string { return t.Name } + +func (t *Tag) ID() string { + return t.RefName() +} diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 9167f8fe7..87d2fba3b 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -3,7 +3,6 @@ package gui import ( "fmt" - "github.com/davecgh/go-spew/spew" "github.com/jesseduffield/gocui" ) @@ -530,7 +529,6 @@ func (gui *Gui) currentSideContext() *ListContext { context := stack[len(stack)-1-i] if context.GetKind() == SIDE_CONTEXT { - gui.Log.Warn(spew.Sdump(context.GetKey())) return context.(*ListContext) } } diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index e152affd1..344cee86b 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -21,7 +21,7 @@ type ListContext struct { OnFocus func() error OnFocusLost func() error OnClickSelectedItem func() error - GetItems func() []ListItem + GetSelectedItem func() ListItem GetPanelState func() IListPanelState Gui *Gui @@ -63,24 +63,6 @@ func (lc *ListContext) GetParentContext() Context { return lc.ParentContext } -func (lc *ListContext) GetSelectedItem() ListItem { - items := lc.GetItems() - - if len(items) == 0 { - return nil - } - - selectedLineIdx := lc.GetPanelState().GetSelectedLineIdx() - - if selectedLineIdx > len(items)-1 { - return nil - } - - item := items[selectedLineIdx] - - return item -} - func (lc *ListContext) GetSelectedItemId() string { item := lc.GetSelectedItem() @@ -287,7 +269,8 @@ func (gui *Gui) filesListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref) }, - Contains: CONTAINS_NOTHING, + Contains: CONTAINS_NOTHING, + GetSelectedItem: func() ListItem { return gui.getSelectedFile() }, } } @@ -304,7 +287,8 @@ func (gui *Gui) branchesListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref) }, - Contains: CONTAINS_COMMITS, + Contains: CONTAINS_COMMITS, + GetSelectedItem: func() ListItem { return gui.getSelectedBranch() }, } } @@ -322,7 +306,8 @@ func (gui *Gui) remotesListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Diff.Ref) }, - Contains: CONTAINS_BRANCHES, + Contains: CONTAINS_BRANCHES, + GetSelectedItem: func() ListItem { return gui.getSelectedRemote() }, } } @@ -339,7 +324,8 @@ func (gui *Gui) remoteBranchesListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Diff.Ref) }, - Contains: CONTAINS_COMMITS, + Contains: CONTAINS_COMMITS, + GetSelectedItem: func() ListItem { return gui.getSelectedRemoteBranch() }, } } @@ -356,7 +342,8 @@ func (gui *Gui) tagsListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref) }, - Contains: CONTAINS_COMMITS, + Contains: CONTAINS_COMMITS, + GetSelectedItem: func() ListItem { return gui.getSelectedTag() }, } } @@ -374,7 +361,8 @@ func (gui *Gui) branchCommitsListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref) }, - Contains: CONTAINS_FILES, + Contains: CONTAINS_FILES, + GetSelectedItem: func() ListItem { return gui.getSelectedCommit() }, } } @@ -391,7 +379,8 @@ func (gui *Gui) reflogCommitsListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref) }, - Contains: CONTAINS_FILES, + Contains: CONTAINS_FILES, + GetSelectedItem: func() ListItem { return gui.getSelectedReflogCommit() }, } } @@ -408,7 +397,8 @@ func (gui *Gui) subCommitsListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref) }, - Contains: CONTAINS_COMMITS, + Contains: CONTAINS_COMMITS, + GetSelectedItem: func() ListItem { return gui.getSelectedSubCommit() }, } } @@ -425,7 +415,8 @@ func (gui *Gui) stashListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Diff.Ref) }, - Contains: CONTAINS_FILES, + Contains: CONTAINS_FILES, + GetSelectedItem: func() ListItem { return gui.getSelectedStashEntry() }, } } @@ -443,7 +434,8 @@ func (gui *Gui) commitFilesListContext() *ListContext { GetDisplayStrings: func() [][]string { return presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref) }, - Contains: CONTAINS_NOTHING, + Contains: CONTAINS_NOTHING, + GetSelectedItem: func() ListItem { return gui.getSelectedCommitFile() }, } }