opencode-vim 0.0.5 → 0.0.6

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.5",
3
+ "version": "0.0.6",
4
4
  "exports": {
5
5
  "./tui": {
6
6
  "import": "./tui.tsx"
@@ -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 = navigationKey(key)
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: true,
179
+ super: false,
160
180
  }
161
181
  }