diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-14 17:29:18 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-14 17:29:18 +0200 |
| commit | feacef91b8114209bd9a87072930a02eb839ce9e (patch) | |
| tree | 0a19f4a8e019da7274583a290be826faffb2d825 /internal/client/ui/viminput/viminput.go | |
| parent | 9c4d6d4616946bdba5f23b267b812856cd2cf75c (diff) | |
Reverted last bug fix, it was a wrong fix that caused a different bug,
the root cause was the SearchChar function which was fixed in this
commit
Diffstat (limited to 'internal/client/ui/viminput/viminput.go')
| -rw-r--r-- | internal/client/ui/viminput/viminput.go | 107 |
1 files changed, 101 insertions, 6 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go index bd78cd6..0008141 100644 --- a/internal/client/ui/viminput/viminput.go +++ b/internal/client/ui/viminput/viminput.go @@ -402,6 +402,9 @@ func (m *Model) Motion(motion string) (line, col int) { if motion == "g" && !m.gmod { m.gmod = true return Unchanged, Unchanged + } else if m.gmod { + m.gmod = false + motion = "g" + motion } else { m.gmod = false } @@ -484,7 +487,7 @@ func (m *Model) Motion(motion string) (line, col int) { } return m.cursorLine + 1, len(line) - 1 - case "g": + case "gg": return 0, Unchanged case "G": return len(m.lines) - 1, Unchanged @@ -793,12 +796,24 @@ func (m *Model) Motion(motion string) (line, col int) { return lnum, 0 } + if remember { + i, ok := SearchCharFunc(line, col, 1, func(c rune) bool { + return !unicode.IsSpace(c) + }) + if !ok { + if isLastLine { + return lnum, len(line) - 1 + } + lnum++ + col = 0 + continue + } + return lnum, i + } + // Search next whitespace - i, ok := SearchCharFunc(line, col + 1, 1, unicode.IsSpace) + i, ok := SearchCharFunc(line, col, 1, unicode.IsSpace) if !ok { - if remember { - return lnum, 0 - } if isLastLine { return lnum, len(line) - 1 } @@ -843,13 +858,29 @@ func (m *Model) Motion(motion string) (line, col int) { return lnum, 0 } + if remember { + i, ok := SearchCharFunc(line, col, 1, func(c rune) bool { + return !unicode.IsSpace(c) + }) + if !ok { + if isLastLine { + return lnum, len(line) - 1 + } + lnum++ + col = 0 + continue + } + return lnum, i + } + + // 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 { + i, ok := SearchCharFunc(line, col, 1, func(c rune) bool { return unicode.IsSpace(c) || isWhitespace || isKeyword != IsKeyword(c) }) if !ok { @@ -880,6 +911,70 @@ func (m *Model) Motion(motion string) (line, col int) { } return lnum, i } + case "gE": + lnum := m.cursorLine + col := m.cursorColumn + remember := false + for { + line := m.lines[lnum] + isFirstLine := lnum == 0 + + // Skip if empty + if len(line) == 0 && !isFirstLine { + // What happens if this is the current line + if lnum == m.cursorLine { + lnum-- + col = len(m.lines[lnum]) - 1 + remember = true + continue + } + return lnum, 0 + } + + if remember { + i, ok := SearchCharFunc(line, col, -1, func(c rune) bool { + return !unicode.IsSpace(c) + }) + if !ok { + if isFirstLine { + return lnum, 0 + } + lnum-- + col = len(m.lines[lnum]) - 1 + continue + } + return lnum, i + } + + // Search next whitespace + i, ok := SearchCharFunc(line, col, -1, unicode.IsSpace) + if !ok { + if isFirstLine { + return lnum, 0 + } + lnum-- + col = len(m.lines[lnum]) - 1 + 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 isFirstLine { + return lnum, 0 + } + lnum-- + col = len(m.lines[lnum]) - 1 + remember = true + continue + } + return lnum, i + } + case "ge": + return Unchanged, m.cursorColumn - 1 default: return Unchanged, Unchanged |
