summaryrefslogtreecommitdiff
path: root/internal/client/ui/viminput/viminput.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/client/ui/viminput/viminput.go')
-rw-r--r--internal/client/ui/viminput/viminput.go59
1 files changed, 58 insertions, 1 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go
index 058e15d..bd78cd6 100644
--- a/internal/client/ui/viminput/viminput.go
+++ b/internal/client/ui/viminput/viminput.go
@@ -794,7 +794,64 @@ func (m *Model) Motion(motion string) (line, col int) {
}
// Search next whitespace
- i, ok := SearchCharFunc(line, col, 1, unicode.IsSpace)
+ i, ok := SearchCharFunc(line, col + 1, 1, unicode.IsSpace)
+ if !ok {
+ if remember {
+ return lnum, 0
+ }
+ if isLastLine {
+ return lnum, len(line) - 1
+ }
+ lnum++
+ col = 0
+ remember = true
+ continue
+ }
+
+ // Search start of next word
+ i, ok = SearchCharFunc(line, i, 1, func(c rune) bool {
+ return !unicode.IsSpace(c)
+ })
+ if !ok {
+ if isLastLine {
+ return lnum, len(line) - 1
+ }
+ lnum++
+ col = 0
+ remember = true
+ continue
+ }
+ return lnum, i
+ }
+ case "w":
+ lnum := m.cursorLine
+ col := m.cursorColumn
+ remember := false
+ for {
+ line := m.lines[lnum]
+ isLastLine := lnum == len(m.lines)-1
+
+ // Skip if empty
+ if len(line) == 0 && !isLastLine {
+ // What happens if this is the current line
+ if lnum == m.cursorLine {
+ lnum++
+ col = 0
+ remember = true
+ continue
+ }
+ return lnum, 0
+ }
+
+ // Search previous non-matching char
+ if col < 0 || len(line) == 0 {
+ return lnum, 0
+ }
+ isKeyword := IsKeyword(line[col])
+ isWhitespace := unicode.IsSpace(line[col])
+ i, ok := SearchCharFunc(line, col + 1, 1, func(c rune) bool {
+ return unicode.IsSpace(c) || isWhitespace || isKeyword != IsKeyword(c)
+ })
if !ok {
if remember {
return lnum, 0