From 010b0ae923360ccaaed34cce6301966bb7c9c9ed Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 17 May 2024 18:13:16 +0200 Subject: [PATCH] Show delete/edit keybindings in suggestions subtitle if available --- pkg/gui/controllers/confirmation_controller.go | 10 ++++++++++ pkg/gui/controllers/helpers/confirmation_helper.go | 1 + pkg/gui/controllers/suggestions_controller.go | 7 +++++-- pkg/i18n/english.go | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/confirmation_controller.go b/pkg/gui/controllers/confirmation_controller.go index aa5617fa8..45bd16a45 100644 --- a/pkg/gui/controllers/confirmation_controller.go +++ b/pkg/gui/controllers/confirmation_controller.go @@ -1,6 +1,8 @@ package controllers import ( + "fmt" + "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -39,6 +41,14 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [ Key: opts.GetKey(opts.Config.Universal.TogglePanel), Handler: func() error { if len(self.c.Contexts().Suggestions.State.Suggestions) > 0 { + subtitle := "" + if self.c.State().GetRepoState().GetCurrentPopupOpts().HandleDeleteSuggestion != nil { + // We assume that whenever things are deletable, they + // are also editable, so we show both keybindings + subtitle = fmt.Sprintf(self.c.Tr.SuggestionsSubtitle, + self.c.UserConfig.Keybinding.Universal.Remove, self.c.UserConfig.Keybinding.Universal.Edit) + } + self.c.Views().Suggestions.Subtitle = subtitle return self.c.ReplaceContext(self.c.Contexts().Suggestions) } return nil diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index e4b76ce40..b5a337fbb 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -159,6 +159,7 @@ func (self *ConfirmationHelper) prepareConfirmationPanel( suggestionsContext.SetSuggestions(opts.FindSuggestionsFunc("")) suggestionsView.Visible = true suggestionsView.Title = fmt.Sprintf(self.c.Tr.SuggestionsTitle, self.c.UserConfig.Keybinding.Universal.TogglePanel) + suggestionsView.Subtitle = "" } self.ResizeConfirmationPanel() diff --git a/pkg/gui/controllers/suggestions_controller.go b/pkg/gui/controllers/suggestions_controller.go index 655c7465b..857952d9b 100644 --- a/pkg/gui/controllers/suggestions_controller.go +++ b/pkg/gui/controllers/suggestions_controller.go @@ -40,8 +40,11 @@ func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) [] Handler: func() error { return self.context().State.OnClose() }, }, { - Key: opts.GetKey(opts.Config.Universal.TogglePanel), - Handler: func() error { return self.c.ReplaceContext(self.c.Contexts().Confirmation) }, + Key: opts.GetKey(opts.Config.Universal.TogglePanel), + Handler: func() error { + self.c.Views().Suggestions.Subtitle = "" + return self.c.ReplaceContext(self.c.Contexts().Confirmation) + }, }, { Key: opts.GetKey(opts.Config.Universal.Remove), diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 27905cf9b..caa920de1 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -631,6 +631,7 @@ type TranslationSet struct { SuggestionsCheatsheetTitle string // Unlike the cheatsheet title above, the real suggestions title has a little message saying press tab to focus SuggestionsTitle string + SuggestionsSubtitle string ExtrasTitle string PushingTagStatus string PullRequestURLCopiedToClipboard string @@ -1593,6 +1594,7 @@ func EnglishTranslationSet() TranslationSet { NavigationTitle: "List panel navigation", SuggestionsCheatsheetTitle: "Suggestions", SuggestionsTitle: "Suggestions (press %s to focus)", + SuggestionsSubtitle: "(press %s to delete, %s to edit)", ExtrasTitle: "Command log", PushingTagStatus: "Pushing tag", PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard",