From b1dd3c48660edea68169779eb860e244b8992427 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 13 Oct 2020 08:16:24 +1100 Subject: [PATCH] support rebinding confirm/newline keys in editor --- docs/Config.md | 2 ++ pkg/commands/commits.go | 8 +++++++- pkg/config/user_config.go | 4 ++++ pkg/gui/commit_message_panel.go | 7 ++++++- pkg/gui/keybindings.go | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index fc2d0ddd3..3e6ea0cbc 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -111,6 +111,8 @@ Default path for the config file: diffingMenu: 'W' diffingMenu-alt: '' # deprecated copyToClipboard: '' + submitEditorText: '' + appendNewline: '' status: checkForUpdate: 'u' recentRepos: '' diff --git a/pkg/commands/commits.go b/pkg/commands/commits.go index 48f0412a2..4d14e1832 100644 --- a/pkg/commands/commits.go +++ b/pkg/commands/commits.go @@ -22,7 +22,13 @@ func (c *GitCommand) ResetToCommit(sha string, strength string, options oscomman // Commit commits to git func (c *GitCommand) Commit(message string, flags string) (*exec.Cmd, error) { - command := fmt.Sprintf("git commit %s -m %s", flags, strconv.Quote(message)) + splitMessage := strings.Split(message, "\n") + lineArgs := "" + for _, line := range splitMessage { + lineArgs += fmt.Sprintf(" -m %s", strconv.Quote(line)) + } + + command := fmt.Sprintf("git commit %s%s", flags, lineArgs) if c.usingGpg() { return c.OSCommand.ShellCommandFromString(command), nil } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 0376fd0fa..d8514db11 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -144,6 +144,8 @@ type KeybindingUniversalConfig struct { DiffingMenu string `yaml:"diffingMenu"` DiffingMenuAlt string `yaml:"diffingMenu-alt"` CopyToClipboard string `yaml:"copyToClipboard"` + SubmitEditorText string `yaml:"submitEditorText"` + AppendNewline string `yaml:"appendNewline"` } type KeybindingStatusConfig struct { @@ -360,6 +362,8 @@ func GetDefaultConfig() *UserConfig { DiffingMenu: "W", DiffingMenuAlt: "", CopyToClipboard: "", + SubmitEditorText: "", + AppendNewline: "", }, Status: KeybindingStatusConfig{ CheckForUpdate: "u", diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 4a5597659..333882467 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -83,6 +83,11 @@ func (gui *Gui) RenderCommitLength() { // we've just copy+pasted the editor from gocui to here so that we can also re- // render the commit message length on each keypress func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { + newlineKey, ok := gui.getKey(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline).(gocui.Key) + if !ok { + newlineKey = gocui.KeyTab + } + switch { case key == gocui.KeyBackspace || key == gocui.KeyBackspace2: v.EditDelete(true) @@ -96,7 +101,7 @@ func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod g v.MoveCursor(-1, 0, false) case key == gocui.KeyArrowRight: v.MoveCursor(1, 0, false) - case key == gocui.KeyTab: + case key == newlineKey: v.EditNewLine() case key == gocui.KeySpace: v.EditWrite(' ') diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index ba3e7a509..2f005a442 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -971,7 +971,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { }, { ViewName: "commitMessage", - Key: gui.getKey(config.Universal.Confirm), + Key: gui.getKey(config.Universal.SubmitEditorText), Modifier: gocui.ModNone, Handler: gui.handleCommitConfirm, },