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

View file

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