11package gui
22
33import (
4- "unicode"
5-
64 "github.com/jesseduffield/gocui"
75)
86
9- func (gui * Gui ) handleEditorKeypress (textArea * gocui.TextArea , key gocui.Key , ch rune , mod gocui.Modifier , allowMultiline bool ) bool {
10- switch {
11- case (key == gocui .KeyBackspace || key == gocui .KeyBackspace2 ) && (mod & gocui .ModAlt ) != 0 ,
12- key == gocui .KeyCtrlW :
13- textArea .BackSpaceWord ()
14- case key == gocui .KeyBackspace || key == gocui .KeyBackspace2 :
15- textArea .BackSpaceChar ()
16- case key == gocui .KeyCtrlD || key == gocui .KeyDelete :
17- textArea .DeleteChar ()
18- case key == gocui .KeyArrowDown :
19- textArea .MoveCursorDown ()
20- case key == gocui .KeyArrowUp :
21- textArea .MoveCursorUp ()
22- case (key == gocui .KeyArrowLeft || ch == 'b' ) && (mod & gocui .ModAlt ) != 0 :
23- textArea .MoveLeftWord ()
24- case key == gocui .KeyArrowLeft || key == gocui .KeyCtrlB :
25- textArea .MoveCursorLeft ()
26- case (key == gocui .KeyArrowRight || ch == 'f' ) && (mod & gocui .ModAlt ) != 0 :
27- textArea .MoveRightWord ()
28- case key == gocui .KeyArrowRight || key == gocui .KeyCtrlF :
29- textArea .MoveCursorRight ()
30- case key == gocui .KeyEnter :
31- if allowMultiline {
32- textArea .TypeCharacter ("\n " )
33- } else {
34- return false
35- }
36- case key == gocui .KeySpace :
37- textArea .TypeCharacter (" " )
38- case key == gocui .KeyInsert :
39- textArea .ToggleOverwrite ()
40- case key == gocui .KeyCtrlU :
41- textArea .DeleteToStartOfLine ()
42- case key == gocui .KeyCtrlK :
43- textArea .DeleteToEndOfLine ()
44- case key == gocui .KeyCtrlA || key == gocui .KeyHome :
45- textArea .GoToStartOfLine ()
46- case key == gocui .KeyCtrlE || key == gocui .KeyEnd :
47- textArea .GoToEndOfLine ()
48- case key == gocui .KeyCtrlY :
49- textArea .Yank ()
50-
51- case unicode .IsPrint (ch ):
52- textArea .TypeCharacter (string (ch ))
53- default :
54- return false
7+ func (gui * Gui ) handleEditorKeypress (v * gocui.View , key gocui.Key , ch rune , mod gocui.Modifier , allowMultiline bool ) bool {
8+ if key == gocui .KeyEnter && allowMultiline {
9+ v .TextArea .TypeCharacter ("\n " )
10+ v .RenderTextArea ()
11+ return true
5512 }
5613
57- return true
14+ return gocui . DefaultEditor . Edit ( v , key , ch , mod )
5815}
5916
6017// we've just copy+pasted the editor from gocui to here so that we can also re-
6118// render the commit message length on each keypress
6219func (gui * Gui ) commitMessageEditor (v * gocui.View , key gocui.Key , ch rune , mod gocui.Modifier ) bool {
63- matched := gui .handleEditorKeypress (v . TextArea , key , ch , mod , false )
20+ matched := gui .handleEditorKeypress (v , key , ch , mod , false )
6421 v .RenderTextArea ()
6522 gui .c .Contexts ().CommitMessage .RenderSubtitle ()
6623 return matched
6724}
6825
6926func (gui * Gui ) commitDescriptionEditor (v * gocui.View , key gocui.Key , ch rune , mod gocui.Modifier ) bool {
70- matched := gui .handleEditorKeypress (v . TextArea , key , ch , mod , true )
27+ matched := gui .handleEditorKeypress (v , key , ch , mod , true )
7128 v .RenderTextArea ()
7229 return matched
7330}
7431
7532func (gui * Gui ) promptEditor (v * gocui.View , key gocui.Key , ch rune , mod gocui.Modifier ) bool {
76- matched := gui .handleEditorKeypress (v . TextArea , key , ch , mod , false )
33+ matched := gui .handleEditorKeypress (v , key , ch , mod , false )
7734
7835 v .RenderTextArea ()
7936
@@ -90,7 +47,7 @@ func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Mo
9047}
9148
9249func (gui * Gui ) searchEditor (v * gocui.View , key gocui.Key , ch rune , mod gocui.Modifier ) bool {
93- matched := gui .handleEditorKeypress (v . TextArea , key , ch , mod , false )
50+ matched := gui .handleEditorKeypress (v , key , ch , mod , false )
9451 v .RenderTextArea ()
9552
9653 searchString := v .TextArea .GetContent ()
0 commit comments