opencode-vim 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/vim/vimee.ts +23 -0
package/package.json
CHANGED
package/src/modules/vim/vimee.ts
CHANGED
|
@@ -62,8 +62,10 @@ export function createVimeeAdapter(state: VimState, config: VimConfig, log: VimL
|
|
|
62
62
|
return true
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const hostEnd = vimeeKey === "e" ? endMotionOffset(map.hostText, offset, vim.count || 1) : undefined
|
|
65
66
|
const result = processKeystroke(vimeeKey, vim, buffer, event.ctrl, false, keybinds)
|
|
66
67
|
vim = result.newCtx
|
|
68
|
+
if (hostEnd !== undefined && result.actions.every((action) => action.type === "cursor-move") && hostEnd > hostOffset(map, vim.cursor, "previous")) vim = { ...vim, cursor: hostPosition(map, hostEnd) }
|
|
67
69
|
applyActions(result.actions as HostAction[], ctx, map)
|
|
68
70
|
syncMode(state, vim.mode)
|
|
69
71
|
const keybindPending = keybinds?.isPending() ?? false
|
|
@@ -278,6 +280,27 @@ function clampNormalCursor(input: EditBufferLike) {
|
|
|
278
280
|
if (cursor.visualRow === eol.visualRow && (cursor.offset === eol.offset || offset === eol.offset)) input.cursorOffset = Math.max(0, offset - 1)
|
|
279
281
|
}
|
|
280
282
|
|
|
283
|
+
function endMotionOffset(text: string, offset: number, count: number) {
|
|
284
|
+
let index = offset
|
|
285
|
+
for (let step = 0; step < count; step++) {
|
|
286
|
+
index++
|
|
287
|
+
while (index < text.length && isWhitespace(text[index])) index++
|
|
288
|
+
const kind = wordKind(text[index])
|
|
289
|
+
if (!kind) return Math.max(0, text.length - 1)
|
|
290
|
+
while (wordKind(text[index + 1]) === kind) index++
|
|
291
|
+
}
|
|
292
|
+
return clamp(index, 0, Math.max(0, text.length - 1))
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function isWhitespace(value: string | undefined) {
|
|
296
|
+
return value === " " || value === "\t" || value === "\n"
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function wordKind(value: string | undefined) {
|
|
300
|
+
if (!value || isWhitespace(value)) return undefined
|
|
301
|
+
return /\w/.test(value) ? "word" : "punctuation"
|
|
302
|
+
}
|
|
303
|
+
|
|
281
304
|
function createKeybinds(config: VimConfig, log: VimLog): KeybindMap | undefined {
|
|
282
305
|
const map = createKeybindMap()
|
|
283
306
|
let count = 0
|