From 7764e6d1cb6d064335c70f5db54cf60b078e867d Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 18 Mar 2024 20:43:08 +0100 Subject: [PATCH] Fix disabling the switch-to-editor menu item if unavailable Some operations don't support switching to the editor from the commit message panel; an example is the commit message panel that appears when moving a custom patch into a new commit. Disable the "open in editor" menu entry in this case, instead of silently doing nothing. --- pkg/gui/controllers/helpers/commits_helper.go | 14 +++++++++----- pkg/i18n/english.go | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 568c07726..8f8904808 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -91,10 +91,6 @@ func TryRemoveHardLineBreaks(message string, autoWrapWidth int) string { } func (self *CommitsHelper) SwitchToEditor() error { - if !self.c.Contexts().CommitMessage.CanSwitchToEditor() { - return nil - } - message := lo.Ternary(len(self.getCommitDescription()) == 0, self.getCommitSummary(), self.getCommitSummary()+"\n\n"+self.getCommitDescription()) @@ -218,13 +214,21 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context { } func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error { + var disabledReasonForOpenInEditor *types.DisabledReason + if !self.c.Contexts().CommitMessage.CanSwitchToEditor() { + disabledReasonForOpenInEditor = &types.DisabledReason{ + Text: self.c.Tr.CommandDoesNotSupportOpeningInEditor, + } + } + menuItems := []*types.MenuItem{ { Label: self.c.Tr.OpenInEditor, OnPress: func() error { return self.SwitchToEditor() }, - Key: 'e', + Key: 'e', + DisabledReason: disabledReasonForOpenInEditor, }, { Label: self.c.Tr.AddCoAuthor, diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index a2a9c1b94..7715001aa 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -775,6 +775,7 @@ type TranslationSet struct { SelectedItemDoesNotHaveFiles string RangeSelectNotSupportedForSubmodules string OldCherryPickKeyWarning string + CommandDoesNotSupportOpeningInEditor string Actions Actions Bisect Bisect Log Log @@ -1731,6 +1732,7 @@ func EnglishTranslationSet() TranslationSet { SelectedItemDoesNotHaveFiles: "Selected item does not have files to view", RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules", OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: \n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'", + CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor", Actions: Actions{ // TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)