From 2b6ec504e536885a47db1e472c5f0de6388fb0ce Mon Sep 17 00:00:00 2001 From: Christopher Vittal Date: Sat, 10 Aug 2019 10:26:46 -0400 Subject: Add delete forward and backward 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], is bound to :prev-field. Leave it up to the user whether or not they want to rebind the key in [compose]. --- lib/ui/textinput.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/ui') diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index e5a2337..00e91ee 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -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() -- cgit v1.2.3