support alt-enter for inserting newline when typing commit message within the app

This commit is contained in:
Jesse Duffield 2021-04-02 15:08:15 +11:00
parent b4827a98ca
commit 1a5f380c00
9 changed files with 27 additions and 17 deletions

View file

@ -5,6 +5,8 @@
package gocui
import (
"unicode"
"github.com/go-errors/errors"
"github.com/mattn/go-runewidth"
@ -53,12 +55,8 @@ func simpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.MoveCursor(-1, 0, false)
case key == KeyArrowRight:
v.MoveCursor(1, 0, false)
case key == KeyTab:
case key == KeyEnter:
v.EditNewLine()
case key == KeySpace:
v.EditWrite(' ')
case key == KeyInsert:
v.Overwrite = !v.Overwrite
case key == KeyCtrlU:
v.EditDeleteToStartOfLine()
case key == KeyCtrlA:
@ -66,12 +64,12 @@ func simpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
case key == KeyCtrlE:
v.EditGotoToEndOfLine()
matched = true
// TODO: see if we need all three of these conditions: maybe the final one is sufficient
case ch != 0 && mod == 0 && unicode.IsPrint(ch):
v.EditWrite(ch)
default:
if ch != 0 && mod == 0 {
v.EditWrite(ch)
} else {
matched = false
}
matched = false
}
return matched

View file

@ -297,7 +297,8 @@ const (
// In tcell, these are not keys per se. But in gocui we have them
// mapped to the keys so we have to use placeholder keys.
MouseLeft = Key(tcell.KeyF63) // arbitrary assignments
KeyAltEnter = Key(tcell.KeyF64) // arbitrary assignments
MouseLeft = Key(tcell.KeyF63)
MouseRight = Key(tcell.KeyF62)
MouseMiddle = Key(tcell.KeyF61)
MouseRelease = Key(tcell.KeyF60)

View file

@ -151,7 +151,14 @@ func pollEvent() GocuiEvent {
// - shift - will be translated to the final code of rune
// - ctrl - is translated in the key
mod = 0
} else if mod == tcell.ModAlt && k == tcell.KeyEnter {
// for the sake of convenience I'm having a KeyAltEnter key. I will likely
// regret this laziness in the future. We're arbitrarily mapping that to tcell's
// KeyF64.
mod = 0
k = tcell.KeyF64
}
return GocuiEvent{
Type: eventKey,
Key: Key(k),