lib/ui/textinput: stop at /, ", and ' chars

This matches the default behaviour of Ctrl+W in vim.
This commit is contained in:
Pranjal Kole 2022-02-03 10:14:04 +05:30 committed by Robin Jarry
parent dc6fd7c15e
commit db1c03f0e6
1 changed files with 11 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package ui
import ( import (
"math" "math"
"strings"
"time" "time"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
@ -188,17 +189,22 @@ func (ti *TextInput) insert(ch rune) {
} }
func (ti *TextInput) deleteWord() { func (ti *TextInput) deleteWord() {
// TODO: Break on any of / " '
if len(ti.text) == 0 || ti.index <= 0 { if len(ti.text) == 0 || ti.index <= 0 {
return return
} }
separators := "/'\""
i := ti.index - 1 i := ti.index - 1
if ti.text[i] == ' ' { for i >= 0 && ti.text[i] == ' ' {
i-- i--
} }
for ; i >= 0; i-- { if strings.ContainsRune(separators, ti.text[i]) {
if ti.text[i] == ' ' { for i >= 0 && strings.ContainsRune(separators, ti.text[i]) {
break i--
}
} else {
separators += " "
for i >= 0 && !strings.ContainsRune(separators, ti.text[i]) {
i--
} }
} }
ti.text = append(ti.text[:i+1], ti.text[ti.index:]...) ti.text = append(ti.text[:i+1], ti.text[ti.index:]...)