summaryrefslogtreecommitdiff
path: root/internal/client
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-12-13 19:31:52 +0200
committerKyren223 <Kyren223@proton.me>2024-12-13 19:31:52 +0200
commite33f4f003a4db4447b0812ba76baa0d0a8388196 (patch)
tree4d3b062483fab744242e8bd0f4e8583772e795c0 /internal/client
parentccb7fca556de6af410fe1342b5b43aa04e927cb0 (diff)
Implemented W motion in viminput (might need some extra testing)
Diffstat (limited to 'internal/client')
-rw-r--r--internal/client/ui/viminput/viminput.go58
1 files changed, 54 insertions, 4 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go
index f860efd..058e15d 100644
--- a/internal/client/ui/viminput/viminput.go
+++ b/internal/client/ui/viminput/viminput.go
@@ -552,7 +552,7 @@ func (m *Model) Motion(motion string) (line, col int) {
}
// Search start of next word
- i, ok = SearchCharFunc(line, col+1, 1, func(c rune) bool {
+ i, ok = SearchCharFunc(line, i, 1, func(c rune) bool {
return !unicode.IsSpace(c)
})
if !ok {
@@ -619,7 +619,7 @@ func (m *Model) Motion(motion string) (line, col int) {
}
// Search start of next word
- i, ok = SearchCharFunc(line, col+1, 1, func(c rune) bool {
+ i, ok = SearchCharFunc(line, i, 1, func(c rune) bool {
return !unicode.IsSpace(c)
})
if !ok {
@@ -680,7 +680,7 @@ func (m *Model) Motion(motion string) (line, col int) {
}
// Search end of previous word
- i, ok = SearchCharFunc(line, col-1, -1, func(c rune) bool {
+ i, ok = SearchCharFunc(line, i, -1, func(c rune) bool {
return !unicode.IsSpace(c)
})
if !ok {
@@ -744,7 +744,7 @@ func (m *Model) Motion(motion string) (line, col int) {
}
// Search end of previous word
- i, ok = SearchCharFunc(line, col-1, -1, func(c rune) bool {
+ i, ok = SearchCharFunc(line, i, -1, func(c rune) bool {
return !unicode.IsSpace(c)
})
if !ok {
@@ -773,6 +773,56 @@ func (m *Model) Motion(motion string) (line, col int) {
}
return lnum, i + 1
}
+ 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 next whitespace
+ i, ok := SearchCharFunc(line, col, 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
+ }
default:
return Unchanged, Unchanged