Skip to content

Commit 7764e6d

Browse files
committed
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.
1 parent 1a9ce9d commit 7764e6d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ func TryRemoveHardLineBreaks(message string, autoWrapWidth int) string {
9191
}
9292

9393
func (self *CommitsHelper) SwitchToEditor() error {
94-
if !self.c.Contexts().CommitMessage.CanSwitchToEditor() {
95-
return nil
96-
}
97-
9894
message := lo.Ternary(len(self.getCommitDescription()) == 0,
9995
self.getCommitSummary(),
10096
self.getCommitSummary()+"\n\n"+self.getCommitDescription())
@@ -218,13 +214,21 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context {
218214
}
219215

220216
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
217+
var disabledReasonForOpenInEditor *types.DisabledReason
218+
if !self.c.Contexts().CommitMessage.CanSwitchToEditor() {
219+
disabledReasonForOpenInEditor = &types.DisabledReason{
220+
Text: self.c.Tr.CommandDoesNotSupportOpeningInEditor,
221+
}
222+
}
223+
221224
menuItems := []*types.MenuItem{
222225
{
223226
Label: self.c.Tr.OpenInEditor,
224227
OnPress: func() error {
225228
return self.SwitchToEditor()
226229
},
227-
Key: 'e',
230+
Key: 'e',
231+
DisabledReason: disabledReasonForOpenInEditor,
228232
},
229233
{
230234
Label: self.c.Tr.AddCoAuthor,

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ type TranslationSet struct {
775775
SelectedItemDoesNotHaveFiles string
776776
RangeSelectNotSupportedForSubmodules string
777777
OldCherryPickKeyWarning string
778+
CommandDoesNotSupportOpeningInEditor string
778779
Actions Actions
779780
Bisect Bisect
780781
Log Log
@@ -1731,6 +1732,7 @@ func EnglishTranslationSet() TranslationSet {
17311732
SelectedItemDoesNotHaveFiles: "Selected item does not have files to view",
17321733
RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules",
17331734
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: <something other than v>\n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'",
1735+
CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor",
17341736

17351737
Actions: Actions{
17361738
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)

0 commit comments

Comments
 (0)