diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-13 17:35:24 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-13 17:35:24 +0200 |
| commit | 29d70f27c508206da27b500ad9b11242bea31acc (patch) | |
| tree | 882304f0893d7bd9c26e5b5f275f0afe1818f584 /internal/client/ui/viminput | |
| parent | c68adab0ba719cfa17f00073435f073ec8183290 (diff) | |
Implemented B motion in vimniput
Diffstat (limited to 'internal/client/ui/viminput')
| -rw-r--r-- | internal/client/ui/viminput/viminput.go | 58 |
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 } |
