opencode-vim
Advanced tools
+1
-1
| { | ||
| "name": "opencode-vim", | ||
| "version": "0.0.7", | ||
| "version": "0.0.8", | ||
| "exports": { | ||
@@ -5,0 +5,0 @@ "./tui": { |
@@ -65,4 +65,6 @@ import type { KeyEvent } from "@opentui/core" | ||
| const hostEnd = vimeeKey === "e" ? endMotionOffset(map.hostText, offset, vim.count || 1) : undefined | ||
| const result = processKeystroke(vimeeKey, vim, buffer, event.ctrl, false, keybinds) | ||
| vim = result.newCtx | ||
| if (hostEnd !== undefined && result.actions.every((action) => action.type === "cursor-move") && hostEnd > hostOffset(map, vim.cursor, "previous")) vim = { ...vim, cursor: hostPosition(map, hostEnd) } | ||
| applyActions(result.actions as HostAction[], ctx, map) | ||
@@ -282,2 +284,23 @@ syncMode(state, vim.mode) | ||
| function endMotionOffset(text: string, offset: number, count: number) { | ||
| let index = offset | ||
| for (let step = 0; step < count; step++) { | ||
| index++ | ||
| while (index < text.length && isWhitespace(text[index])) index++ | ||
| const kind = wordKind(text[index]) | ||
| if (!kind) return Math.max(0, text.length - 1) | ||
| while (wordKind(text[index + 1]) === kind) index++ | ||
| } | ||
| return clamp(index, 0, Math.max(0, text.length - 1)) | ||
| } | ||
| function isWhitespace(value: string | undefined) { | ||
| return value === " " || value === "\t" || value === "\n" | ||
| } | ||
| function wordKind(value: string | undefined) { | ||
| if (!value || isWhitespace(value)) return undefined | ||
| return /\w/.test(value) ? "word" : "punctuation" | ||
| } | ||
| function createKeybinds(config: VimConfig, log: VimLog): KeybindMap | undefined { | ||
@@ -284,0 +307,0 @@ const map = createKeybindMap() |
373791
0.28%2257
0.89%