2020-11-28 04:14:48 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2021-03-21 01:12:17 +02:00
|
|
|
"unicode"
|
|
|
|
|
2020-11-28 04:14:48 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2021-02-18 10:39:33 +02:00
|
|
|
func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool {
|
2020-11-28 04:14:48 +02:00
|
|
|
newlineKey, ok := gui.getKey(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline).(gocui.Key)
|
|
|
|
if !ok {
|
2021-04-02 06:08:15 +02:00
|
|
|
newlineKey = gocui.KeyAltEnter
|
2020-11-28 04:14:48 +02:00
|
|
|
}
|
|
|
|
|
2021-02-18 10:39:33 +02:00
|
|
|
matched := true
|
2020-11-28 04:14:48 +02:00
|
|
|
switch {
|
|
|
|
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
|
|
|
|
v.EditDelete(true)
|
2021-02-18 10:39:33 +02:00
|
|
|
case key == gocui.KeyCtrlD || key == gocui.KeyDelete:
|
2020-11-28 04:14:48 +02:00
|
|
|
v.EditDelete(false)
|
|
|
|
case key == gocui.KeyArrowDown:
|
|
|
|
v.MoveCursor(0, 1, false)
|
|
|
|
case key == gocui.KeyArrowUp:
|
|
|
|
v.MoveCursor(0, -1, false)
|
|
|
|
case key == gocui.KeyArrowLeft:
|
|
|
|
v.MoveCursor(-1, 0, false)
|
|
|
|
case key == gocui.KeyArrowRight:
|
|
|
|
v.MoveCursor(1, 0, false)
|
|
|
|
case key == newlineKey:
|
|
|
|
v.EditNewLine()
|
|
|
|
case key == gocui.KeySpace:
|
|
|
|
v.EditWrite(' ')
|
|
|
|
case key == gocui.KeyInsert:
|
|
|
|
v.Overwrite = !v.Overwrite
|
|
|
|
case key == gocui.KeyCtrlU:
|
|
|
|
v.EditDeleteToStartOfLine()
|
|
|
|
case key == gocui.KeyCtrlA:
|
|
|
|
v.EditGotoToStartOfLine()
|
|
|
|
case key == gocui.KeyCtrlE:
|
|
|
|
v.EditGotoToEndOfLine()
|
2021-04-02 05:38:09 +02:00
|
|
|
|
|
|
|
// TODO: see if we need all three of these conditions: maybe the final one is sufficient
|
|
|
|
case ch != 0 && mod == 0 && unicode.IsPrint(ch):
|
2020-11-28 04:14:48 +02:00
|
|
|
v.EditWrite(ch)
|
2021-04-02 05:38:09 +02:00
|
|
|
default:
|
|
|
|
matched = false
|
2020-11-28 04:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gui.RenderCommitLength()
|
2021-02-18 10:39:33 +02:00
|
|
|
|
|
|
|
return matched
|
2020-11-28 04:14:48 +02:00
|
|
|
}
|
|
|
|
|
2021-02-18 10:39:33 +02:00
|
|
|
func (gui *Gui) defaultEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool {
|
|
|
|
matched := true
|
2020-11-28 04:14:48 +02:00
|
|
|
switch {
|
|
|
|
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
|
|
|
|
v.EditDelete(true)
|
2021-02-18 10:39:33 +02:00
|
|
|
case key == gocui.KeyCtrlD || key == gocui.KeyDelete:
|
2020-11-28 04:14:48 +02:00
|
|
|
v.EditDelete(false)
|
|
|
|
case key == gocui.KeyArrowDown:
|
|
|
|
v.MoveCursor(0, 1, false)
|
|
|
|
case key == gocui.KeyArrowUp:
|
|
|
|
v.MoveCursor(0, -1, false)
|
|
|
|
case key == gocui.KeyArrowLeft:
|
|
|
|
v.MoveCursor(-1, 0, false)
|
|
|
|
case key == gocui.KeyArrowRight:
|
|
|
|
v.MoveCursor(1, 0, false)
|
|
|
|
case key == gocui.KeySpace:
|
|
|
|
v.EditWrite(' ')
|
|
|
|
case key == gocui.KeyInsert:
|
|
|
|
v.Overwrite = !v.Overwrite
|
|
|
|
case key == gocui.KeyCtrlU:
|
|
|
|
v.EditDeleteToStartOfLine()
|
|
|
|
case key == gocui.KeyCtrlA:
|
|
|
|
v.EditGotoToStartOfLine()
|
|
|
|
case key == gocui.KeyCtrlE:
|
|
|
|
v.EditGotoToEndOfLine()
|
2021-04-02 05:38:09 +02:00
|
|
|
|
|
|
|
// TODO: see if we need all three of these conditions: maybe the final one is sufficient
|
|
|
|
case ch != 0 && mod == 0 && unicode.IsPrint(ch):
|
2020-11-28 04:14:48 +02:00
|
|
|
v.EditWrite(ch)
|
2021-04-02 05:38:09 +02:00
|
|
|
default:
|
|
|
|
matched = false
|
2020-11-28 04:14:48 +02:00
|
|
|
}
|
|
|
|
|
2020-11-28 11:01:45 +02:00
|
|
|
if gui.findSuggestions != nil {
|
|
|
|
input := v.Buffer()
|
|
|
|
suggestions := gui.findSuggestions(input)
|
|
|
|
gui.setSuggestions(suggestions)
|
2020-11-28 04:14:48 +02:00
|
|
|
}
|
2021-02-18 10:39:33 +02:00
|
|
|
|
|
|
|
return matched
|
2020-11-28 04:14:48 +02:00
|
|
|
}
|