opencode-vim-navigation 0.1.4 → 0.1.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/adapter.mjs +27 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-vim-navigation",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Modal Vim-style transcript navigation for the OpenCode terminal UI",
5
5
  "license": "MIT",
6
6
  "author": "Raaghav Arya",
package/src/adapter.mjs CHANGED
@@ -16,7 +16,7 @@ export function createSetup({ InputRenderable, TextareaRenderable, createElement
16
16
  const route = ui.router.current()
17
17
  return route.type === "session" ? route.sessionID : undefined
18
18
  }
19
- const promptFocused = () => {
19
+ const promptEditor = () => {
20
20
  const editor = renderer.currentFocusedEditor
21
21
  const traits = editor?.traits
22
22
  return editor instanceof TextareaRenderable && !(editor instanceof InputRenderable)
@@ -24,6 +24,23 @@ export function createSetup({ InputRenderable, TextareaRenderable, createElement
24
24
  && !traits.status
25
25
  && !traits.capture?.includes("navigate") && !traits.capture?.includes("submit")
26
26
  && !traits.capture?.includes("autocomplete")
27
+ ? editor
28
+ : undefined
29
+ }
30
+ const promptFocused = () => promptEditor() !== undefined
31
+ let hiddenCursor
32
+ const restoreCursor = () => {
33
+ if (!hiddenCursor) return
34
+ if (!hiddenCursor.editor.isDestroyed) hiddenCursor.editor.showCursor = hiddenCursor.showCursor
35
+ hiddenCursor = undefined
36
+ }
37
+ const syncCursor = (active = nav()) => {
38
+ const editor = active ? promptEditor() : undefined
39
+ if (hiddenCursor && hiddenCursor.editor !== editor) restoreCursor()
40
+ if (editor && !hiddenCursor && editor.showCursor === true && !editor.isDestroyed) {
41
+ hiddenCursor = { editor, showCursor: true }
42
+ editor.showCursor = false
43
+ }
27
44
  }
28
45
  const visibleForms = () => {
29
46
  const id = session()
@@ -66,9 +83,15 @@ export function createSetup({ InputRenderable, TextareaRenderable, createElement
66
83
  return false
67
84
  },
68
85
  dispatch: (id) => keymap.dispatch(id),
69
- changed: setNav,
86
+ changed: (active) => {
87
+ setNav(active)
88
+ syncCursor(active)
89
+ },
70
90
  })
71
- const cleanups = [() => controller.leave()]
91
+ const cleanups = [() => {
92
+ controller.leave()
93
+ syncCursor(false)
94
+ }]
72
95
  let cleaned = false
73
96
  const cleanup = () => {
74
97
  if (cleaned) return
@@ -95,6 +118,7 @@ export function createSetup({ InputRenderable, TextareaRenderable, createElement
95
118
  planReviewForm()
96
119
  promptFocused()
97
120
  controller.sync()
121
+ syncCursor()
98
122
  })
99
123
  })
100
124
  cleanups.push(ui.slot({