1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-01-26 01:41:35 +03:00

Call gocui's SimpleEditor instead of duplicating its code

This commit is contained in:
Stefan Haller
2025-12-13 15:51:22 +01:00
parent 5423e7459c
commit bb816d7001

View File

@@ -1,79 +1,36 @@
package gui
import (
"unicode"
"github.com/jesseduffield/gocui"
)
func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch rune, mod gocui.Modifier, allowMultiline bool) bool {
switch {
case (key == gocui.KeyBackspace || key == gocui.KeyBackspace2) && (mod&gocui.ModAlt) != 0,
key == gocui.KeyCtrlW:
textArea.BackSpaceWord()
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
textArea.BackSpaceChar()
case key == gocui.KeyCtrlD || key == gocui.KeyDelete:
textArea.DeleteChar()
case key == gocui.KeyArrowDown:
textArea.MoveCursorDown()
case key == gocui.KeyArrowUp:
textArea.MoveCursorUp()
case (key == gocui.KeyArrowLeft || ch == 'b') && (mod&gocui.ModAlt) != 0:
textArea.MoveLeftWord()
case key == gocui.KeyArrowLeft || key == gocui.KeyCtrlB:
textArea.MoveCursorLeft()
case (key == gocui.KeyArrowRight || ch == 'f') && (mod&gocui.ModAlt) != 0:
textArea.MoveRightWord()
case key == gocui.KeyArrowRight || key == gocui.KeyCtrlF:
textArea.MoveCursorRight()
case key == gocui.KeyEnter:
if allowMultiline {
textArea.TypeCharacter("\n")
} else {
return false
}
case key == gocui.KeySpace:
textArea.TypeCharacter(" ")
case key == gocui.KeyInsert:
textArea.ToggleOverwrite()
case key == gocui.KeyCtrlU:
textArea.DeleteToStartOfLine()
case key == gocui.KeyCtrlK:
textArea.DeleteToEndOfLine()
case key == gocui.KeyCtrlA || key == gocui.KeyHome:
textArea.GoToStartOfLine()
case key == gocui.KeyCtrlE || key == gocui.KeyEnd:
textArea.GoToEndOfLine()
case key == gocui.KeyCtrlY:
textArea.Yank()
case unicode.IsPrint(ch):
textArea.TypeCharacter(string(ch))
default:
return false
func (gui *Gui) handleEditorKeypress(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier, allowMultiline bool) bool {
if key == gocui.KeyEnter && allowMultiline {
v.TextArea.TypeCharacter("\n")
v.RenderTextArea()
return true
}
return true
return gocui.DefaultEditor.Edit(v, key, ch, mod)
}
// 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, false)
matched := gui.handleEditorKeypress(v, key, ch, mod, false)
v.RenderTextArea()
gui.c.Contexts().CommitMessage.RenderSubtitle()
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)
matched := gui.handleEditorKeypress(v, key, ch, mod, true)
v.RenderTextArea()
return matched
}
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)
matched := gui.handleEditorKeypress(v, key, ch, mod, false)
v.RenderTextArea()
@@ -90,7 +47,7 @@ func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Mo
}
func (gui *Gui) searchEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool {
matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false)
matched := gui.handleEditorKeypress(v, key, ch, mod, false)
v.RenderTextArea()
searchString := v.TextArea.GetContent()