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