Add delete forward <C-k> and backward <C-u>

Choose the readline defaults for the behavior of these two
functions/keybindings. Depending on the program, either of these can
delete the whole line.

Note that by default in [compose], <C-k> is bound to :prev-field<Enter>.
Leave it up to the user whether or not they want to rebind the key in
[compose].
This commit is contained in:
Christopher Vittal 2019-08-10 10:26:46 -04:00 committed by Drew DeVault
parent 4d95676274
commit 2b6ec504e5
1 changed files with 29 additions and 0 deletions

View File

@ -151,6 +151,29 @@ func (ti *TextInput) deleteWord() {
ti.onChange()
}
func (ti *TextInput) deleteLineForward() {
if len(ti.text) == 0 || len(ti.text) == ti.index {
return
}
ti.text = ti.text[:ti.index]
ti.ensureScroll()
ti.Invalidate()
ti.onChange()
}
func (ti *TextInput) deleteLineBackward() {
if len(ti.text) == 0 || ti.index == 0 {
return
}
ti.text = ti.text[ti.index:]
ti.index = 0
ti.ensureScroll()
ti.Invalidate()
ti.onChange()
}
func (ti *TextInput) deleteChar() {
if len(ti.text) > 0 && ti.index != len(ti.text) {
ti.text = append(ti.text[:ti.index], ti.text[ti.index+1:]...)
@ -249,9 +272,15 @@ func (ti *TextInput) Event(event tcell.Event) bool {
ti.index = len(ti.text)
ti.ensureScroll()
ti.Invalidate()
case tcell.KeyCtrlK:
ti.invalidateCompletions()
ti.deleteLineForward()
case tcell.KeyCtrlW:
ti.invalidateCompletions()
ti.deleteWord()
case tcell.KeyCtrlU:
ti.invalidateCompletions()
ti.deleteLineBackward()
case tcell.KeyTab:
if ti.tabcomplete != nil {
ti.nextCompletion()