add readline shortcuts to textbox (ctrl+w, ctrl+u, ctrl+k)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user