From 41f69052b52c452416cbc5114a3e004e9c8d233d Mon Sep 17 00:00:00 2001 From: Username Date: Tue, 24 Feb 2026 10:02:09 +0100 Subject: [PATCH] add readline shortcuts to textbox (ctrl+w, ctrl+u, ctrl+k) --- uiterm/textbox.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/uiterm/textbox.go b/uiterm/textbox.go index 5f97043..2651352 100644 --- a/uiterm/textbox.go +++ b/uiterm/textbox.go @@ -63,9 +63,12 @@ func (t *Textbox) uiDraw() { func (t *Textbox) uiKeyEvent(mod Modifier, key Key) { redraw := false switch key { - case KeyCtrlC: + case KeyCtrlC, KeyCtrlU, KeyCtrlK: t.Text = "" redraw = true + case KeyCtrlW: + t.Text = deleteWord(t.Text) + redraw = true case KeyEnter: if t.Input != nil { t.Input(t.ui, t, t.Text) @@ -91,6 +94,16 @@ func (t *Textbox) uiKeyEvent(mod Modifier, key Key) { } } +func deleteWord(s string) string { + // Trim trailing spaces, then trim non-spaces (the word) + s = strings.TrimRight(s, " ") + i := strings.LastIndex(s, " ") + if i < 0 { + return "" + } + return s[:i+1] +} + func (t *Textbox) uiCharacterEvent(chr rune) { if len(t.Text) >= maxTextboxLen { return