summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-03-18 20:43:08 +0100
committerStefan Haller <stefan@haller-berlin.de>2024-03-18 21:10:58 +0100
commit7764e6d1cb6d064335c70f5db54cf60b078e867d (patch)
tree3e748e446446ff0cffc403abdc394d0f8f3ec002
parent1a9ce9db947d170647b8dcfea2be4172997ff7ed (diff)
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.
-rw-r--r--pkg/gui/controllers/helpers/commits_helper.go14
-rw-r--r--pkg/i18n/english.go2
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: <something other than v>\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)