diff options
-rw-r--r-- | pkg/commands/branch.go | 4 | ||||
-rw-r--r-- | pkg/commands/commit.go | 4 | ||||
-rw-r--r-- | pkg/commands/remote.go | 4 | ||||
-rw-r--r-- | pkg/commands/remote_branch.go | 4 | ||||
-rw-r--r-- | pkg/commands/tag.go | 4 | ||||
-rw-r--r-- | pkg/gui/diffing.go | 86 | ||||
-rw-r--r-- | pkg/gui/list_context.go | 2 |
7 files changed, 60 insertions, 48 deletions
diff --git a/pkg/commands/branch.go b/pkg/commands/branch.go index ad37985fd..27ac548a8 100644 --- a/pkg/commands/branch.go +++ b/pkg/commands/branch.go @@ -12,3 +12,7 @@ type Branch struct { UpstreamName string Head bool } + +func (b *Branch) RefName() string { + return b.Name +} diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go index f8f7491b4..1058e8ec6 100644 --- a/pkg/commands/commit.go +++ b/pkg/commands/commit.go @@ -24,3 +24,7 @@ func (c *Commit) ShortSha() string { func (c *Commit) NameWithSha() string { return fmt.Sprintf("%s %s", c.Sha[:7], c.Name) } + +func (c *Commit) RefName() string { + return c.Sha +} diff --git a/pkg/commands/remote.go b/pkg/commands/remote.go index 1dc9f7e7f..264e6a2c4 100644 --- a/pkg/commands/remote.go +++ b/pkg/commands/remote.go @@ -6,3 +6,7 @@ type Remote struct { Urls []string Branches []*RemoteBranch } + +func (r *Remote) RefName() string { + return r.Name +} diff --git a/pkg/commands/remote_branch.go b/pkg/commands/remote_branch.go index ca39ac4c1..0c7352d06 100644 --- a/pkg/commands/remote_branch.go +++ b/pkg/commands/remote_branch.go @@ -9,3 +9,7 @@ type RemoteBranch struct { func (r *RemoteBranch) FullName() string { return r.RemoteName + "/" + r.Name } + +func (r *RemoteBranch) RefName() string { + return r.FullName() +} diff --git a/pkg/commands/tag.go b/pkg/commands/tag.go index b6910b4b0..71a250c40 100644 --- a/pkg/commands/tag.go +++ b/pkg/commands/tag.go @@ -4,3 +4,7 @@ package commands type Tag struct { Name string } + +func (t *Tag) RefName() string { + return t.Name +} diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 789552659..ff52bdeb9 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/commands" ) func (gui *Gui) inDiffMode() bool { @@ -42,62 +41,55 @@ func (gui *Gui) renderDiff() error { // which becomes an option when you bring up the diff menu, but when you're just // flicking through branches it will be using the local branch name. func (gui *Gui) currentDiffTerminals() []string { - currentView := gui.g.CurrentView() - if currentView == nil { - return nil - } - names := []string{} - switch currentView.Name() { + switch gui.currentContextKey() { case "files": // not supporting files for now - - case "commitFiles": + case "commit-files": // not supporting commit files for now - - case "commits": - var commit *commands.Commit - switch gui.getCommitsView().Context { - case "reflog-commits": - commit = gui.getSelectedReflogCommit() - case "branch-commits": - commit = gui.getSelectedCommit() + case "branch-commits": + item := gui.getSelectedCommit() + if item != nil { + return []string{item.RefName()} } - if commit != nil { - names = append(names, commit.Sha) + case "reflog-commits": + item := gui.getSelectedReflogCommit() + if item != nil { + return []string{item.RefName()} } case "stash": - entry := gui.getSelectedStashEntry() - if entry != nil { - names = append(names, entry.RefName()) + item := gui.getSelectedStashEntry() + if item != nil { + return []string{item.RefName()} } - case "branches": - switch gui.getBranchesView().Context { - case "local-branches": - branch := gui.getSelectedBranch() - if branch != nil { - names = append(names, branch.Name) - if branch.UpstreamName != "" { - names = append(names, branch.UpstreamName) - } - } - case "remotes": - remote := gui.getSelectedRemote() - if remote != nil { - names = append(names, remote.Name) - } - case "remote-branches": - remoteBranch := gui.getSelectedRemoteBranch() - if remoteBranch != nil { - names = append(names, remoteBranch.FullName()) - } - case "tags": - tag := gui.getSelectedTag() - if tag != nil { - names = append(names, tag.Name) + + case "local-branches": + branch := gui.getSelectedBranch() + if branch != nil { + names := []string{branch.RefName()} + if branch.UpstreamName != "" { + names = append(names, branch.UpstreamName) } + return names + } + return nil + case "remotes": + item := gui.getSelectedRemote() + if item != nil { + return []string{item.RefName()} + } + case "remote-branches": + item := gui.getSelectedRemoteBranch() + if item != nil { + return []string{item.RefName()} + } + case "tags": + item := gui.getSelectedTag() + if item != nil { + return []string{item.RefName()} } } - return names + + return nil } func (gui *Gui) currentDiffTerminal() string { diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 98e62cbc1..79195a873 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -326,7 +326,7 @@ func (gui *Gui) stashListContext() *ListContext { func (gui *Gui) commitFilesListContext() *ListContext { return &ListContext{ ViewName: "commitFiles", - ContextKey: "commitFiles", + ContextKey: "commit-files", GetItemsLength: func() int { return len(gui.State.CommitFiles) }, GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine }, OnFocus: gui.handleCommitFileSelect, |