summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-12-13 17:35:24 +0200
committerKyren223 <Kyren223@proton.me>2024-12-13 17:35:24 +0200
commit29d70f27c508206da27b500ad9b11242bea31acc (patch)
tree882304f0893d7bd9c26e5b5f275f0afe1818f584 /internal
parentc68adab0ba719cfa17f00073435f073ec8183290 (diff)
Implemented B motion in vimniput
Diffstat (limited to 'internal')
-rw-r--r--internal/client/ui/viminput/viminput.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go
index 274b7f0..8a5d96c 100644
--- a/internal/client/ui/viminput/viminput.go
+++ b/internal/client/ui/viminput/viminput.go
@@ -577,6 +577,64 @@ func (m *Model) Motion(motion string) (line, col int) {
}
return lnum, i - 1
}
+ case "B":
+ lnum := m.cursorLine
+ col := m.cursorColumn
+ for {
+ line := m.lines[lnum]
+ isFirstLine := lnum == 0
+ isColAtStart := col == 0
+
+ // Skip if empty
+ if len(line) == 0 && !isFirstLine {
+ lnum--
+ col = len(m.lines[lnum]) - 1
+ continue
+ }
+
+ // Search previous whitespace
+ i, ok := SearchCharFunc(line, col-1, -1, unicode.IsSpace)
+ if !ok {
+ if isFirstLine || !isColAtStart {
+ return lnum, 0
+ }
+ lnum--
+ col = len(m.lines[lnum]) - 1
+ continue
+ }
+
+ // Found next word - Simple case
+ if i+1 != col {
+ return lnum, i + 1
+ }
+
+ // Search end of previous word
+ i, ok = SearchCharFunc(line, col-1, -1, func(c rune) bool {
+ return !unicode.IsSpace(c)
+ })
+ if !ok {
+ if isFirstLine {
+ return lnum, 0
+ }
+ lnum--
+ col = len(m.lines[lnum]) - 1
+ continue
+ }
+
+ // Previous word exists, find it's start
+ i, ok = SearchCharFunc(line, i, -1, unicode.IsSpace)
+ if !ok {
+ if isFirstLine || !isColAtStart {
+ return lnum, 0
+ }
+ // If at the start, continue to previous line (if it exists)
+ lnum--
+ col = len(m.lines[lnum]) - 1
+ continue
+ }
+ return lnum, i + 1
+ }
+
default:
return Unchanged, Unchanged
}