opencode-vim 0.0.6 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-vim",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "exports": {
5
5
  "./tui": {
6
6
  "import": "./tui.tsx"
@@ -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
package/src/update.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { rm } from "node:fs/promises"
2
- import { dirname, join } from "node:path"
2
+ import { basename, dirname, join } from "node:path"
3
3
  import { fileURLToPath } from "node:url"
4
4
  import type { TuiPluginMeta } from "@opencode-ai/plugin/tui"
5
5
 
6
6
  type PackageJson = {
7
7
  name?: string
8
8
  version?: string
9
+ dependencies?: Record<string, string>
9
10
  }
10
11
 
11
12
  type UpdateResult =
@@ -25,8 +26,9 @@ export async function checkAutoUpdate(meta: TuiPluginMeta, signal: AbortSignal):
25
26
  const latest = await fetchLatestVersion(pkg.name, signal)
26
27
  if (!latest || !isVersionNewer(latest, pkg.version)) return { updated: false }
27
28
 
29
+ const removeDir = await updateRemoveDir(packageDir, pkg.name)
28
30
  try {
29
- await rm(packageDir, { recursive: true, force: true })
31
+ await rm(removeDir, { recursive: true, force: true })
30
32
  } catch {
31
33
  return { updated: false, error: "remove_failed", name: pkg.name, current: pkg.version, latest }
32
34
  }
@@ -47,6 +49,15 @@ async function findPackageDir() {
47
49
  }
48
50
  }
49
51
 
52
+ async function updateRemoveDir(packageDir: string, name: string) {
53
+ const nodeModulesDir = dirname(packageDir)
54
+ if (basename(nodeModulesDir) !== "node_modules") return packageDir
55
+
56
+ const wrapperDir = dirname(nodeModulesDir)
57
+ const wrapperPkg = await readPackageJson(join(wrapperDir, "package.json"))
58
+ return wrapperPkg?.dependencies?.[name] ? wrapperDir : packageDir
59
+ }
60
+
50
61
  async function readPackageJson(path: string): Promise<PackageJson | undefined> {
51
62
  try {
52
63
  const file = Bun.file(path)