opencode-vim 0.0.5 → 0.0.7
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/index.tsx +23 -3
- package/src/update.ts +13 -2
package/package.json
CHANGED
|
@@ -111,7 +111,7 @@ function readablePending(sequence: string) {
|
|
|
111
111
|
|
|
112
112
|
function passThroughKey(event: KeyEvent, key: string, mode: string) {
|
|
113
113
|
if (mode !== "normal") return false
|
|
114
|
-
return event.super === true || isArrowKey(key) || key === "<CR>"
|
|
114
|
+
return event.super === true || isArrowKey(key) || key === "<CR>" || key === "<C-c>"
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
function preparePassThroughKey(ctx: PromptContext, key: string, mode: string) {
|
|
@@ -123,7 +123,7 @@ function preparePassThroughKey(ctx: PromptContext, key: string, mode: string) {
|
|
|
123
123
|
|
|
124
124
|
function sendNavigationKey(event: KeyEvent, ctx: PromptContext, key: string, mode: string) {
|
|
125
125
|
if (mode !== "normal") return false
|
|
126
|
-
const forwarded =
|
|
126
|
+
const forwarded = commandNavigationKey(ctx, key)
|
|
127
127
|
if (!forwarded) return false
|
|
128
128
|
|
|
129
129
|
event.preventDefault()
|
|
@@ -132,6 +132,26 @@ function sendNavigationKey(event: KeyEvent, ctx: PromptContext, key: string, mod
|
|
|
132
132
|
return true
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
function commandNavigationKey(ctx: PromptContext, key: string): ParsedKey | undefined {
|
|
136
|
+
if (!isPromptFocused(ctx)) return navigationKey(key)
|
|
137
|
+
if (!isSlashCommandToken(ctx)) return undefined
|
|
138
|
+
if (key === "j") return arrowKey("down", "\u001B[B")
|
|
139
|
+
if (key === "k") return arrowKey("up", "\u001B[A")
|
|
140
|
+
return undefined
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isPromptFocused(ctx: PromptContext) {
|
|
144
|
+
return ctx.prompt()?.focused === true && !!focusedInput(ctx)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function isSlashCommandToken(ctx: PromptContext) {
|
|
148
|
+
const text = ctx.prompt()?.current.input ?? focusedInput(ctx)?.plainText ?? ""
|
|
149
|
+
if (!text.startsWith("/")) return false
|
|
150
|
+
const input = focusedInput(ctx)
|
|
151
|
+
const offset = Math.max(0, input?.cursorOffset ?? text.length)
|
|
152
|
+
return !/\s/.test(text.slice(0, Math.min(offset + 1, text.length)))
|
|
153
|
+
}
|
|
154
|
+
|
|
135
155
|
function navigationKey(key: string): ParsedKey | undefined {
|
|
136
156
|
if (key === "h") return arrowKey("left", "\u001B[D")
|
|
137
157
|
if (key === "j") return arrowKey("down", "\u001B[B")
|
|
@@ -156,6 +176,6 @@ function arrowKey(name: string, sequence: string): ParsedKey {
|
|
|
156
176
|
raw: sequence,
|
|
157
177
|
eventType: "press",
|
|
158
178
|
source: "raw",
|
|
159
|
-
super:
|
|
179
|
+
super: false,
|
|
160
180
|
}
|
|
161
181
|
}
|
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(
|
|
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)
|