~sircmpwn/aerc

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

Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/%3C20190810142646.24727-1-christopher.vittal%40gmail.com%3E/mbox | git am -3
Learn more about email & git

[PATCH] Add delete forward <C-k> and backward <C-u> Export this patch

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].
---
 lib/ui/textinput.go | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

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()
-- 
2.22.0
View this thread in the archives