diff options
author | Sean <seand52@gmail.com> | 2023-01-21 11:38:14 +0000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:53 +1000 |
commit | 9d68b287db57b49eddf4b2b81ca1acd2e16aa5aa (patch) | |
tree | d286af9a7cfa27348fb5034ee01a1e16a699057b /pkg/gui/editors.go | |
parent | a5c72d056ddbd639db3597ffb19a60e0cbae1826 (diff) |
Split commit message panel into commit summary and commit description panel
When we use the one panel for the entire commit message, its tricky to have a keybinding both for adding a newline and submitting.
By having two panels: one for the summary line and one for the description, we allow for 'enter' to submit the message when done from the summary panel,
and 'enter' to add a newline when done from the description panel. Alt-enter, for those who can use that key combo, also works for submitting the message
from the description panel. For those who can't use that key combo, and don't want to remap the keybinding, they can hit tab to go back to the summary panel
and then 'enter' to submit the message.
We have some awkwardness in that both contexts (i.e. panels) need to appear and disappear in tandem and we don't have a great way of handling that concept,
so we just push both contexts one after the other, and likewise remove both contexts when we escape.
Diffstat (limited to 'pkg/gui/editors.go')
-rw-r--r-- | pkg/gui/editors.go | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/pkg/gui/editors.go b/pkg/gui/editors.go index 4325a56f4..1fbba2aad 100644 --- a/pkg/gui/editors.go +++ b/pkg/gui/editors.go @@ -4,15 +4,9 @@ import ( "unicode" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/gui/keybindings" ) func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch rune, mod gocui.Modifier, allowMultiline bool) bool { - newlineKey, ok := keybindings.GetKey(gui.c.UserConfig.Keybinding.Universal.AppendNewline).(gocui.Key) - if !ok { - newlineKey = gocui.KeyAltEnter - } - switch { case key == gocui.KeyBackspace || key == gocui.KeyBackspace2: textArea.BackSpaceChar() @@ -30,7 +24,7 @@ func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch textArea.MoveRightWord() case key == gocui.KeyArrowRight || key == gocui.KeyCtrlF: textArea.MoveCursorRight() - case key == newlineKey: + case key == gocui.KeyEnter: if allowMultiline { textArea.TypeRune('\n') } else { @@ -66,22 +60,20 @@ func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch // 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) bool { - matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, true) - - // This function is called again on refresh as part of the general resize popup call, - // but we need to call it here so that when we go to render the text area it's not - // considered out of bounds to add a newline, meaning we can avoid unnecessary scrolling. - err := gui.helpers.Confirmation.ResizePopupPanel(v, v.TextArea.GetContent()) - if err != nil { - gui.c.Log.Error(err) - } + matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false) v.RenderTextArea() - gui.State.Contexts.CommitMessage.RenderCommitLength() + gui.c.Contexts().CommitMessage.RenderCommitLength() + return matched +} +func (gui *Gui) commitDescriptionEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool { + matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, true) + v.RenderTextArea() + gui.c.Contexts().CommitMessage.RenderCommitLength() return matched } -func (gui *Gui) defaultEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool { +func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool { matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false) v.RenderTextArea() |