summaryrefslogtreecommitdiff
path: root/internal/client/ui
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-12-14 16:23:42 +0200
committerKyren223 <Kyren223@proton.me>2024-12-14 16:23:42 +0200
commit9c4d6d4616946bdba5f23b267b812856cd2cf75c (patch)
tree7d964a9989a3ae90b79e42fe12dee3bb53109b5a /internal/client/ui
parente33f4f003a4db4447b0812ba76baa0d0a8388196 (diff)
Implemented w motion in viminput and fixed a bug with w/W when on the
start of the line it'd jump to the next (even if a word in the current line exists)
Diffstat (limited to 'internal/client/ui')
-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