diff options
Diffstat (limited to 'pkg')
27 files changed, 267 insertions, 157 deletions
diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index d20a0c71a..6c641fa1f 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -131,16 +131,19 @@ func getBindingSections(bindings []*types.Binding, tr *i18n.TranslationSet) []*b return getHeaders(binding, tr) }) - bindingGroups := maps.MapToSlice(bindingsByHeader, func(header header, hBindings []*types.Binding) headerWithBindings { - uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string { - return binding.Description + gui.GetKeyDisplay(binding.Key) - }) - - return headerWithBindings{ - header: header, - bindings: uniqBindings, - } - }) + bindingGroups := maps.MapToSlice( + bindingsByHeader, + func(header header, hBindings []*types.Binding) headerWithBindings { + uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string { + return binding.Description + gui.GetKeyDisplay(binding.Key) + }) + + return headerWithBindings{ + header: header, + bindings: uniqBindings, + } + }, + ) slices.SortFunc(bindingGroups, func(a, b headerWithBindings) bool { if a.header.priority != b.header.priority { @@ -169,18 +172,11 @@ func getHeaders(binding *types.Binding, tr *i18n.TranslationSet) []header { } if len(binding.Contexts) == 0 { - translatedView := localisedTitle(tr, binding.ViewName) - title := fmt.Sprintf("%s %s", translatedView, tr.Panel) - - return []header{{priority: 1, title: title}} + return []header{} } return slices.Map(binding.Contexts, func(context string) header { - translatedView := localisedTitle(tr, binding.ViewName) - translatedContextName := localisedTitle(tr, context) - title := fmt.Sprintf("%s %s (%s)", translatedView, tr.Panel, translatedContextName) - - return header{priority: 1, title: title} + return header{priority: 1, title: localisedTitle(tr, context)} }) } @@ -205,7 +201,12 @@ func formatTitle(title string) string { func formatBinding(binding *types.Binding) string { if binding.Alternative != "" { - return fmt.Sprintf(" <kbd>%s</kbd>: %s (%s)\n", gui.GetKeyDisplay(binding.Key), binding.Description, binding.Alternative) + return fmt.Sprintf( + " <kbd>%s</kbd>: %s (%s)\n", + gui.GetKeyDisplay(binding.Key), + binding.Description, + binding.Alternative, + ) } return fmt.Sprintf(" <kbd>%s</kbd>: %s\n", gui.GetKeyDisplay(binding.Key), binding.Description) } diff --git a/pkg/cheatsheet/generate_test.go b/pkg/cheatsheet/generate_test.go index 94b571454..149ed28c7 100644 --- a/pkg/cheatsheet/generate_test.go +++ b/pkg/cheatsheet/generate_test.go @@ -26,38 +26,18 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, }, expected: []*bindingSection{ { - title: "Files Panel", - bindings: []*types.Binding{ - { - ViewName: "files", - Description: "stage file", - }, - }, - }, - }, - }, - { - testName: "one binding with context", - bindings: []*types.Binding{ - { - ViewName: "files", - Description: "stage file", - Contexts: []string{"submodules"}, - }, - }, - expected: []*bindingSection{ - { - title: "Files Panel (Submodules)", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", - Contexts: []string{"submodules"}, }, }, }, @@ -101,23 +81,10 @@ func TestGetBindingSections(t *testing.T) { Description: "drop submodule", Contexts: []string{"submodules"}, }, - { - ViewName: "commits", - Description: "revert commit", - }, }, expected: []*bindingSection{ { - title: "Commits Panel", - bindings: []*types.Binding{ - { - ViewName: "commits", - Description: "revert commit", - }, - }, - }, - { - title: "Files Panel (Files)", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", @@ -132,7 +99,7 @@ func TestGetBindingSections(t *testing.T) { }, }, { - title: "Files Panel (Submodules)", + title: "Submodules", bindings: []*types.Binding{ { ViewName: "files", @@ -148,19 +115,23 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, }, @@ -170,29 +141,33 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, }, }, { - title: "Commits Panel", + title: "Commits", bindings: []*types.Binding{ { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, }, }, { - title: "Files Panel", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, }, @@ -204,28 +179,34 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "page up", Tag: "navigation", }, @@ -236,34 +217,39 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "page up", Tag: "navigation", }, }, }, { - title: "Commits Panel", + title: "Commits", bindings: []*types.Binding{ { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, }, }, { - title: "Files Panel", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, }, diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 4f292d3eb..a93486b07 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -41,6 +41,7 @@ func (gui *Gui) commitFilesRenderToMain() error { func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesContextOpts) error { gui.State.Contexts.CommitFiles.SetSelectedLineIdx(0) gui.State.Contexts.CommitFiles.SetRefName(opts.RefName) + gui.State.Contexts.CommitFiles.SetTitleRef(opts.RefDescription) gui.State.Contexts.CommitFiles.SetCanRebase(opts.CanRebase) gui.State.Contexts.CommitFiles.SetParentContext(opts.Context) gui.State.Contexts.CommitFiles.SetWindowName(opts.Context.GetWindowName()) @@ -54,7 +55,8 @@ func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesC func (gui *Gui) refreshCommitFilesContext() error { currentSideContext := gui.currentSideContext() - if currentSideContext.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || currentSideContext.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { + if currentSideContext.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || + currentSideContext.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { if err := gui.handleRefreshPatchBuildingPanel(-1); err != nil { return err } diff --git a/pkg/gui/context.go b/pkg/gui/context.go index c02411640..c63defba4 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -151,8 +151,7 @@ func (gui *Gui) deactivateContext(c types.Context) error { if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || - c.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || - c.GetKey() == context.SUB_COMMITS_CONTEXT_KEY) { + c.IsTransient()) { view.Visible = false } @@ -393,11 +392,7 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error _ = oldView.SetOriginX(0) if !lo.Contains([]*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Search}, newView) { - transientContexts := slices.Filter(gui.State.Contexts.Flatten(), func(context types.Context) bool { - return context.IsTransient() - }) - - for _, context := range transientContexts { + for _, context := range gui.TransientContexts() { if oldView.Name() == context.GetViewName() { if err := gui.deactivateContext(context); err != nil { return err @@ -409,6 +404,12 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error return nil } +func (gui *Gui) TransientContexts() []types.Context { + return slices.Filter(gui.State.Contexts.Flatten(), func(context types.Context) bool { + return context.IsTransient() + }) +} + // changeContext is a helper function for when we want to change a 'main' context // which currently just means a context that affects both the main and secondary views // other views can have their context changed directly but this function helps diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index e5de639d9..302f0c1d9 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -65,3 +65,13 @@ func (self *BranchesContext) GetSelectedRefName() string { return item.RefName() } + +func (self *BranchesContext) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index 5ad7144dc..c95486cbf 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -1,18 +1,16 @@ package context import ( - "fmt" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/types" - "github.com/jesseduffield/lazygit/pkg/utils" ) type CommitFilesContext struct { *filetree.CommitFileTreeViewModel *ListContextTrait + *DynamicTitleBuilder } var _ types.IListContext = (*CommitFilesContext)(nil) @@ -32,6 +30,7 @@ func NewCommitFilesContext( return &CommitFilesContext{ CommitFileTreeViewModel: viewModel, + DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.CommitFilesDynamicTitle), ListContextTrait: &ListContextTrait{ Context: NewSimpleContext( NewBaseContext(NewBaseContextOpts{ @@ -63,7 +62,3 @@ func (self *CommitFilesContext) GetSelectedItemId() string { return item.ID() } - -func (self *CommitFilesContext) Title() string { - return fmt.Sprintf(self.c.Tr.CommitFilesDynamicTitle, utils.TruncateWithEllipsis(self.GetRefName(), 50)) -} diff --git a/pkg/gui/context/context.go b/pkg/gui/context/context.go index add336cfd..fb5a4bd64 100644 --- a/pkg/gui/context/context.go +++ b/pkg/gui/context/context.go @@ -152,11 +152,8 @@ func (tree ContextTree) InitialViewTabContextMap() map[string][]TabContext { Contexts: []types.Context{tree.Branches}, }, { - Tab: "Remotes", - Contexts: []types.Context{ - tree.Remotes, - tree.RemoteBranches, - }, + Tab: "Remotes", + Contexts: []types.Context{tree.Remotes}, }, { Tab: "Tags", @@ -169,10 +166,8 @@ func (tree ContextTree) InitialViewTabContextMap() map[string][]TabContext { Contexts: []types.Context{tree.LocalCommits}, }, { - Tab: "Reflog", - Contexts: []types.Context{ - tree.ReflogCommits, - }, + Tab: "Reflog", + Contexts: []types.Context{tree.ReflogCommits}, }, }, "files": { @@ -181,10 +176,8 @@ func (tree ContextTree) InitialViewTabContextMap() map[string][]TabContext { Contexts: []types.Context{tree.Files}, }, { - Tab: "Submodules", - Contexts: []types.Context{ - tree.Submodules, - }, + Tab: "Submodules", + Contexts: []types.Context{tree.Submodules}, }, }, } diff --git a/pkg/gui/context/dynamic_title_builder.go b/pkg/gui/context/dynamic_title_builder.go new file mode 100644 index 000000000..ee4facad2 --- /dev/null +++ b/pkg/gui/context/dynamic_title_builder.go @@ -0,0 +1,23 @@ +package context + +import "fmt" + +type DynamicTitleBuilder struct { + formatStr string // e.g. 'remote branches for %s' + + titleRef string // e.g. 'origin' +} + +func NewDynamicTitleBuilder(formatStr string) *DynamicTitleBuilder { + return &DynamicTitleBuilder{ + formatStr: formatStr, + } +} + +func (self *DynamicTitleBuilder) SetTitleRef(titleRef string) { + self.titleRef = titleRef +} + +func (self *DynamicTitleBuilder) Title() string { + return fmt.Sprintf(self.formatStr, self.titleRef) +} diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index cc7a2a0d2..0d7cc2f54 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -93,6 +93,16 @@ func (self *LocalCommitsContext) GetSelectedRefName() string { return item.RefName() } +func (self *LocalCommitsViewModel) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} + func (self *LocalCommitsViewModel) SetLimitCommits(value bool) { self.limitCommits = value } diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index a1ad6cfda..0274a921e 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -74,3 +74,13 @@ func (self *ReflogCommitsContext) GetSelectedRefName() string { func (self *ReflogCommitsContext) GetCommits() []*models.Commit { return self.getModel() } + +func (self *ReflogCommitsContext) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index 3cdd43a69..52217ef11 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -9,6 +9,7 @@ import ( type RemoteBranchesContext struct { *BasicViewModel[*models.RemoteBranch] *ListContextTrait + *DynamicTitleBuilder } var _ types.IListContext = (*RemoteBranchesContext)(nil) @@ -27,14 +28,16 @@ func NewRemoteBranchesContext( viewModel := NewBasicViewModel(getModel) return &RemoteBranchesContext{ - BasicViewModel: viewModel, + BasicViewModel: viewModel, + DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.RemoteBranchesDynamicTitle), ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - ViewName: "branches", + ViewName: "remoteBranches", WindowName: "branches", Key: REMOTE_BRANCHES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, Focusable: true, + Transient: true, }), ContextCallbackOpts{ OnFocus: onFocus, OnFocusLost: onFocusLost, @@ -65,3 +68,13 @@ func (self *RemoteBranchesContext) GetSelectedRefName() string { return item.RefName() } + +func (self *RemoteBranchesContext) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index e2af64d10..ef443846f 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -70,3 +70,13 @@ func (self *StashContext) GetSelectedRefName() string { return item.RefName() } + +func (self *StashContext) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 6c1d5910f..ffc053267 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -12,6 +12,7 @@ import ( type SubCommitsContext struct { *SubCommitsViewModel *ViewportListContextTrait + *DynamicTitleBuilder } var _ types.IListContext = (*SubCommitsContext)(nil) @@ -34,6 +35,7 @@ func NewSubCommitsContext( return &SubCommitsContext{ SubCommitsViewModel: viewModel, + DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.SubCommitsDynamicTitle), ViewportListContextTrait: &ViewportListContextTrait{ ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ @@ -99,3 +101,13 @@ func (self *SubCommitsContext) GetCommits() []*models.Commit { func (self *SubCommitsContext) Title() string { return fmt.Sprintf(self.c.Tr.SubCommitsDynamicTitle, utils.TruncateWithEllipsis(self.refName, 50)) } + +func (self *SubCommitsContext) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index fd411ec9a..d6f8d78ac 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -65,3 +65,13 @@ func (self *TagsContext) GetSelectedRefName() string { return item.RefName() } + +func (self *TagsContext) GetSelectedDescription() string { + item := self.GetSelected() + + if item == nil { + return "" + } + + return item.Description() +} diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 41433068d..1df223365 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -497,9 +497,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err func (self *LocalCommitsController) squashAllAboveFixupCommits(commit *models.Commit) error { prompt := utils.ResolvePlaceholderString( self.c.Tr.SureSquashAboveCommits, - map[string]string{ - "commit": commit.Sha, - }, + map[string]string{"commit": commit.Sha}, ) return self.c.Ask(types.AskOpts{ @@ -561,7 +559,9 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { } return self.c.WithWaitingStatus(self.c.Tr.LcLoadingCommits, func() error { - return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}) + return self.c.Refresh( + types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}, + ) }) }, }, @@ -602,7 +602,12 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { return func() error { self.c.UserConfig.Git.Log.Order = value return self.c.WithWaitingStatus(self.c.Tr.LcLoadingCommits, func() error { - return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}) + return self.c.Refresh( + types.RefreshOptions{ + Mode: types.SYNC, + Scope: []types.RefreshableView{types.COMMITS}, + }, + ) }) } } diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index fd4b34297..208f36af7 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -73,6 +73,11 @@ func (self *RemotesController) enter(remote *models.Remote) error { newSelectedLine = -1 } self.contexts.RemoteBranches.SetSelectedLineIdx(newSelectedLine) + self.contexts.RemoteBranches.SetTitleRef(remote.Name) + + if err := self.c.PostRefreshUpdate(self.contexts.RemoteBranches); err != nil { + return err + } return self.c.PushContext(self.contexts.RemoteBranches) } diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 9a3111cae..c41dbdd37 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -12,6 +12,7 @@ type CanSwitchToDiffFiles interface { types.Context CanRebase() bool GetSelectedRefName() string + GetSelectedDescription() string } type SwitchToDiffFilesController struct { @@ -63,9 +64,10 @@ func (self *SwitchToDiffFilesController) checkSelected(callback func(string) err func (self *SwitchToDiffFilesController) enter(refName string) error { return self.viewFiles(SwitchToCommitFilesContextOpts{ - RefName: refName, - CanRebase: self.context.CanRebase(), - Context: self.context, + RefName: refName, + RefDescription: self.context.GetSelectedDescription(), + CanRebase: self.context.CanRebase(), + Context: self.context, }) } diff --git a/pkg/gui/controllers/switch_to_sub_commits_controller.go b/pkg/gui/controllers/switch_to_sub_commits_controller.go index 82b52509b..d59f4fdbf 100644 --- a/pkg/gui/controllers/switch_to_sub_commits_controller.go +++ b/pkg/gui/controllers/switch_to_sub_commits_controller.go @@ -11,6 +11,7 @@ var _ types.IController = &SwitchToSubCommitsController{} type CanSwitchToSubCommits interface { types.Context GetSelectedRefName() string + GetSelectedDescription() string } type SwitchToSubCommitsController struct { @@ -74,6 +75,7 @@ func (self *SwitchToSubCommitsController) viewCommits() error { self.contexts.SubCommits.SetSelectedLineIdx(0) self.contexts.SubCommits.SetParentContext(self.context) self.contexts.SubCommits.SetWindowName(self.context.GetWindowName()) + self.contexts.SubCommits.SetTitleRef(self.context.GetSelectedDescription()) self.contexts.SubCommits.SetRefName(refName) err = self.c.PostRefreshUpdate(self.contexts.SubCommits) diff --git a/pkg/gui/controllers/types.go b/pkg/gui/controllers/types.go index 9783ca3b7..e9af41089 100644 --- a/pkg/gui/controllers/types.go +++ b/pkg/gui/controllers/types.go @@ -6,7 +6,17 @@ import ( // all fields mandatory (except `CanRebase` because it's boolean) type SwitchToCommitFilesContextOpts struct { - RefName string + // this is something like a commit sha or branch name + RefName string + + // this will be displayed in the title of the view so we know whose diff files + // we're viewing + RefDescription string + + // from the local commits view we're allowed to do rebase stuff with any patch + // we generate from the diff files context, but we don't have that same ability + // with say the sub c |