Skip to content

Commit 5d30409

Browse files
authored
Add an alternate keybinding (default <c-s>) for ConfirmInEditor (#4532)
- **PR Description** The default binding for ConfirmInEditor is <a-enter>, 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 `<c-enter>` instead (and Command-Enter on Mac), but neither is possible without gdamore/tcell#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 `<disabled>`. 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.
2 parents c3081ef + 450239d commit 5d30409

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

docs/Config.md

+1
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ keybinding:
516516
goInto: <enter>
517517
confirm: <enter>
518518
confirmInEditor: <a-enter>
519+
confirmInEditor-alt: <c-s>
519520
remove: d
520521
new: "n"
521522
edit: e

pkg/config/user_config.go

+2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ type KeybindingUniversalConfig struct {
405405
GoInto string `yaml:"goInto"`
406406
Confirm string `yaml:"confirm"`
407407
ConfirmInEditor string `yaml:"confirmInEditor"`
408+
ConfirmInEditorAlt string `yaml:"confirmInEditor-alt"`
408409
Remove string `yaml:"remove"`
409410
New string `yaml:"new"`
410411
Edit string `yaml:"edit"`
@@ -882,6 +883,7 @@ func GetDefaultConfig() *UserConfig {
882883
GoInto: "<enter>",
883884
Confirm: "<enter>",
884885
ConfirmInEditor: "<a-enter>",
886+
ConfirmInEditorAlt: "<c-s>",
885887
Remove: "d",
886888
New: "n",
887889
Edit: "e",

pkg/gui/controllers/commit_description_controller.go

+25-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOp
3838
Key: opts.GetKey(opts.Config.Universal.ConfirmInEditor),
3939
Handler: self.confirm,
4040
},
41+
{
42+
Key: opts.GetKey(opts.Config.Universal.ConfirmInEditorAlt),
43+
Handler: self.confirm,
44+
},
4145
{
4246
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
4347
Handler: self.openCommitMenu,
@@ -63,10 +67,27 @@ func (self *CommitDescriptionController) GetMouseKeybindings(opts types.Keybindi
6367

6468
func (self *CommitDescriptionController) GetOnFocus() func(types.OnFocusOpts) {
6569
return func(types.OnFocusOpts) {
66-
self.c.Views().CommitDescription.Footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
67-
map[string]string{
68-
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
69-
})
70+
footer := ""
71+
if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor != "<disabled>" || self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt != "<disabled>" {
72+
if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor == "<disabled>" {
73+
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
74+
map[string]string{
75+
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt),
76+
})
77+
} else if self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt == "<disabled>" {
78+
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
79+
map[string]string{
80+
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
81+
})
82+
} else {
83+
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooterTwoBindings,
84+
map[string]string{
85+
"confirmInEditorKeybinding1": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
86+
"confirmInEditorKeybinding2": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt),
87+
})
88+
}
89+
}
90+
self.c.Views().CommitDescription.Footer = footer
7091
}
7192
}
7293

pkg/i18n/english.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ type TranslationSet struct {
330330
CommitDescriptionTitle string
331331
CommitDescriptionSubTitle string
332332
CommitDescriptionFooter string
333+
CommitDescriptionFooterTwoBindings string
333334
CommitHooksDisabledSubTitle string
334335
LocalBranchesTitle string
335336
SearchTitle string
@@ -1410,7 +1411,8 @@ func EnglishTranslationSet() *TranslationSet {
14101411
CommitSummaryTitle: "Commit summary",
14111412
CommitDescriptionTitle: "Commit description",
14121413
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
1413-
CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to commit",
1414+
CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to submit",
1415+
CommitDescriptionFooterTwoBindings: "Press {{.confirmInEditorKeybinding1}} or {{.confirmInEditorKeybinding2}} to submit",
14141416
CommitHooksDisabledSubTitle: "(hooks disabled)",
14151417
LocalBranchesTitle: "Local branches",
14161418
SearchTitle: "Search",

schema/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,10 @@
13101310
"type": "string",
13111311
"default": "\u003ca-enter\u003e"
13121312
},
1313+
"confirmInEditor-alt": {
1314+
"type": "string",
1315+
"default": "\u003cc-s\u003e"
1316+
},
13131317
"remove": {
13141318
"type": "string",
13151319
"default": "d"

0 commit comments

Comments
 (0)