summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorChristopher Vittal <christopher.vittal@gmail.com>2019-08-10 10:26:46 -0400
committerDrew DeVault <sir@cmpwn.com>2019-08-12 09:27:48 +0900
commit2b6ec504e536885a47db1e472c5f0de6388fb0ce (patch)
tree3dd29294f7bb1b3cdfd4e7eb63b3c216b2aa9383 /lib/ui
parent4d956762746812e8e13a5a08b52801f62833c96c (diff)
downloadaerc-2b6ec504e536885a47db1e472c5f0de6388fb0ce.tar.gz
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].
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/textinput.go29
1 files changed, 29 insertions, 0 deletions
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()