From 2b22ad165111ed7c9d632e4686b446e1141a18ff Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 3 May 2025 17:22:18 +0200 Subject: [PATCH] Add an alternate keybinding (default ) for ConfirmInEditor The default binding for ConfirmInEditor is , which has two problems: - some terminal emulators don't support it, including the default terminal on Mac (Terminal.app) - on Windows it is bound to toggling full-screen Ideally we would use instead (and Command-Enter on Mac), but neither is possible without https://github.com/gdamore/tcell/issues/671, so for the time being add an alternate keybinding which works everywhere. Show both bindings in the footer of the commit description panel if they are both non-null. While we're at it, fix the footer for the case where either or both of the keybindings are set to . And finally, change "commit" to "submit" in that footer; we use the same panel also for creating tags, in which case "commit" is not quite right. --- docs/Config.md | 1 + pkg/config/user_config.go | 2 ++ .../commit_description_controller.go | 29 ++++++++++++++++--- pkg/i18n/english.go | 4 ++- schema/config.json | 4 +++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 8fd1fd960c0..c94cc633e70 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -515,6 +515,7 @@ keybinding: goInto: confirm: confirmInEditor: + confirmInEditor-alt: remove: d new: "n" edit: e diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index d35e35772e9..c23b7682421 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -408,6 +408,7 @@ type KeybindingUniversalConfig struct { GoInto string `yaml:"goInto"` Confirm string `yaml:"confirm"` ConfirmInEditor string `yaml:"confirmInEditor"` + ConfirmInEditorAlt string `yaml:"confirmInEditor-alt"` Remove string `yaml:"remove"` New string `yaml:"new"` Edit string `yaml:"edit"` @@ -892,6 +893,7 @@ func GetDefaultConfig() *UserConfig { GoInto: "", Confirm: "", ConfirmInEditor: "", + ConfirmInEditorAlt: "", Remove: "d", New: "n", Edit: "e", diff --git a/pkg/gui/controllers/commit_description_controller.go b/pkg/gui/controllers/commit_description_controller.go index 4337a1e4b0d..1247de076e5 100644 --- a/pkg/gui/controllers/commit_description_controller.go +++ b/pkg/gui/controllers/commit_description_controller.go @@ -38,6 +38,10 @@ func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOp Key: opts.GetKey(opts.Config.Universal.ConfirmInEditor), Handler: self.confirm, }, + { + Key: opts.GetKey(opts.Config.Universal.ConfirmInEditorAlt), + Handler: self.confirm, + }, { Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu), Handler: self.openCommitMenu, @@ -63,10 +67,27 @@ func (self *CommitDescriptionController) GetMouseKeybindings(opts types.Keybindi func (self *CommitDescriptionController) GetOnFocus() func(types.OnFocusOpts) { return func(types.OnFocusOpts) { - self.c.Views().CommitDescription.Footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter, - map[string]string{ - "confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor), - }) + footer := "" + if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor != "" || self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt != "" { + if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor == "" { + footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter, + map[string]string{ + "confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt), + }) + } else if self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt == "" { + footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter, + map[string]string{ + "confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor), + }) + } else { + footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooterTwoBindings, + map[string]string{ + "confirmInEditorKeybinding1": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor), + "confirmInEditorKeybinding2": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt), + }) + } + } + self.c.Views().CommitDescription.Footer = footer } } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index a85f7202fdc..5577103148c 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -330,6 +330,7 @@ type TranslationSet struct { CommitDescriptionTitle string CommitDescriptionSubTitle string CommitDescriptionFooter string + CommitDescriptionFooterTwoBindings string CommitHooksDisabledSubTitle string LocalBranchesTitle string SearchTitle string @@ -1408,7 +1409,8 @@ func EnglishTranslationSet() *TranslationSet { CommitSummaryTitle: "Commit summary", CommitDescriptionTitle: "Commit description", CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu", - CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to commit", + CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to submit", + CommitDescriptionFooterTwoBindings: "Press {{.confirmInEditorKeybinding1}} or {{.confirmInEditorKeybinding2}} to submit", CommitHooksDisabledSubTitle: "(hooks disabled)", LocalBranchesTitle: "Local branches", SearchTitle: "Search", diff --git a/schema/config.json b/schema/config.json index 96a968e4d10..02fb4f79721 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1313,6 +1313,10 @@ "type": "string", "default": "\u003ca-enter\u003e" }, + "confirmInEditor-alt": { + "type": "string", + "default": "\u003cc-s\u003e" + }, "remove": { "type": "string", "default": "d"