aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui
diff options
context:
space:
mode:
authorPranjal Kole <pranjal.kole7@gmail.com>2022-02-03 10:14:04 +0530
committerRobin Jarry <robin@jarry.cc>2022-02-03 13:17:10 +0100
commitdb1c03f0e614b88dddba62063b6f92b47c7de08b (patch)
tree6b68a792d4be89f02c190bb4218a318867ae1193 /lib/ui
parentdc6fd7c15e15fd1ec6a3b48a1367432a63bf4aaf (diff)
downloadaerc-db1c03f0e614b88dddba62063b6f92b47c7de08b.tar.gz
lib/ui/textinput: stop at /, ", and ' chars
This matches the default behaviour of Ctrl+W in vim.
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/textinput.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index cd31d267..59af7cc8 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -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:]...)