opencode-vim 0.0.9 → 0.0.10
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 +7 -6
- package/src/modules/vim/view.tsx +11 -2
- package/src/plugin.tsx +19 -1
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { KeyEvent, ParsedKey } from "@opentui/core"
|
|
3
3
|
import { useKeyboard } from "@opentui/solid"
|
|
4
4
|
import { onCleanup } from "solid-js"
|
|
5
|
+
import type { Accessor } from "solid-js"
|
|
5
6
|
import type { PromptContext, PromptModule } from "../../prompt/types"
|
|
6
7
|
import { applyVimCursorStyle, focusedInput } from "./actions"
|
|
7
8
|
import type { VimConfig } from "./config"
|
|
@@ -13,7 +14,7 @@ import { createVimState } from "./state"
|
|
|
13
14
|
import { createVimeeAdapter } from "./vimee"
|
|
14
15
|
import { VimStatus } from "./view"
|
|
15
16
|
|
|
16
|
-
export function createVimModule(options?: unknown): PromptModule {
|
|
17
|
+
export function createVimModule(options?: unknown, enabled: Accessor<boolean> = () => true): PromptModule {
|
|
17
18
|
const config = createVimConfig(options)
|
|
18
19
|
const log = createVimLog(config)
|
|
19
20
|
const state = createVimState(config.defaultMode, log)
|
|
@@ -26,15 +27,15 @@ export function createVimModule(options?: unknown): PromptModule {
|
|
|
26
27
|
log("module.setup", { kind: ctx.kind, sessionID: ctx.sessionID, workspaceID: ctx.workspaceID })
|
|
27
28
|
},
|
|
28
29
|
renderAbove(ctx) {
|
|
29
|
-
return <VimKeyboard ctx={ctx} config={config} state={state} log={log} />
|
|
30
|
+
return <VimKeyboard ctx={ctx} config={config} state={state} enabled={enabled} log={log} />
|
|
30
31
|
},
|
|
31
32
|
renderRight(ctx) {
|
|
32
|
-
return <VimStatus mode={state.mode} pending={() => readablePending(state.pending())} theme={ctx.api.theme.current} pendingDisplayDelay={config.pendingDisplayDelay} disabled={ctx.disabled} log={log} requestRender={ctx.requestRender} />
|
|
33
|
+
return <VimStatus mode={state.mode} pending={() => readablePending(state.pending())} enabled={enabled} theme={ctx.api.theme.current} pendingDisplayDelay={config.pendingDisplayDelay} disabled={ctx.disabled} log={log} requestRender={ctx.requestRender} />
|
|
33
34
|
},
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
function VimKeyboard(props: { ctx: PromptContext; config: VimConfig; state: ReturnType<typeof createVimState>; log: VimLog }) {
|
|
38
|
+
function VimKeyboard(props: { ctx: PromptContext; config: VimConfig; state: ReturnType<typeof createVimState>; enabled: Accessor<boolean>; log: VimLog }) {
|
|
38
39
|
let cursorStyleMode = ""
|
|
39
40
|
const vimee = createVimeeAdapter(props.state, props.config, props.log)
|
|
40
41
|
props.log("keyboard.mount", { kind: props.ctx.kind })
|
|
@@ -53,8 +54,8 @@ function VimKeyboard(props: { ctx: PromptContext; config: VimConfig; state: Retu
|
|
|
53
54
|
pending: props.state.pending(),
|
|
54
55
|
})
|
|
55
56
|
|
|
56
|
-
if (props.ctx.disabled || props.ctx.visible === false) {
|
|
57
|
-
props.log("keyboard.skip", { disabled: props.ctx.disabled, visible: props.ctx.visible })
|
|
57
|
+
if (!props.enabled() || props.ctx.disabled || props.ctx.visible === false) {
|
|
58
|
+
props.log("keyboard.skip", { enabled: props.enabled(), disabled: props.ctx.disabled, visible: props.ctx.visible })
|
|
58
59
|
return
|
|
59
60
|
}
|
|
60
61
|
|
package/src/modules/vim/view.tsx
CHANGED
|
@@ -10,6 +10,7 @@ const STATUS_SYNC_MS = 50
|
|
|
10
10
|
type VimStatusProps = {
|
|
11
11
|
mode: Accessor<VimMode>
|
|
12
12
|
pending: Accessor<string | undefined>
|
|
13
|
+
enabled: Accessor<boolean>
|
|
13
14
|
theme: PromptContext["api"]["theme"]["current"]
|
|
14
15
|
pendingDisplayDelay?: number
|
|
15
16
|
disabled?: boolean
|
|
@@ -20,6 +21,7 @@ type VimStatusProps = {
|
|
|
20
21
|
export function VimStatus(props: VimStatusProps) {
|
|
21
22
|
const [mode, setMode] = createSignal(props.mode())
|
|
22
23
|
const [pending, setPending] = createSignal<string | undefined>()
|
|
24
|
+
const [enabled, setEnabled] = createSignal(props.enabled())
|
|
23
25
|
let pendingTimer: ReturnType<typeof setTimeout> | undefined
|
|
24
26
|
let scheduledPending: string | undefined
|
|
25
27
|
|
|
@@ -33,6 +35,13 @@ export function VimStatus(props: VimStatusProps) {
|
|
|
33
35
|
props.requestRender?.()
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
const nextEnabled = props.enabled()
|
|
39
|
+
if (enabled() !== nextEnabled) {
|
|
40
|
+
props.log?.("status.enabled", { from: enabled(), to: nextEnabled })
|
|
41
|
+
setEnabled(nextEnabled)
|
|
42
|
+
props.requestRender?.()
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
syncPending(nextPending)
|
|
37
46
|
}
|
|
38
47
|
|
|
@@ -44,8 +53,8 @@ export function VimStatus(props: VimStatusProps) {
|
|
|
44
53
|
|
|
45
54
|
return (
|
|
46
55
|
<box paddingLeft={1} paddingRight={1} flexDirection="row">
|
|
47
|
-
{pending() ? <text fg={props.theme.info}>{pending()} </text> : undefined}
|
|
48
|
-
<text fg={props.disabled ? props.theme.textMuted : mode() === "insert" ? props.theme.success : props.theme.warning}>{modeLabel(mode())}</text>
|
|
56
|
+
{enabled() && pending() ? <text fg={props.theme.info}>{pending()} </text> : undefined}
|
|
57
|
+
{enabled() ? <text fg={props.disabled ? props.theme.textMuted : mode() === "insert" ? props.theme.success : props.theme.warning}>{modeLabel(mode())}</text> : undefined}
|
|
49
58
|
</box>
|
|
50
59
|
)
|
|
51
60
|
|
package/src/plugin.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
|
3
|
+
import { createSignal } from "solid-js"
|
|
3
4
|
import { PromptRoot } from "./prompt/root"
|
|
4
5
|
import type { PromptModule } from "./prompt/types"
|
|
5
6
|
import { createVimModule } from "./modules/vim"
|
|
@@ -7,6 +8,23 @@ import { createSnippetsModule } from "./modules/snippets"
|
|
|
7
8
|
import { checkAutoUpdate } from "./update"
|
|
8
9
|
|
|
9
10
|
const tui: TuiPlugin = async (api, options, meta) => {
|
|
11
|
+
const vimEnabledKey = `${meta.id}:enabled`
|
|
12
|
+
const [vimEnabled, setVimEnabled] = createSignal(api.kv.get(vimEnabledKey, true) === true)
|
|
13
|
+
|
|
14
|
+
api.command.register(() => [{
|
|
15
|
+
title: vimEnabled() ? "Disable Vim Mode" : "Enable Vim Mode",
|
|
16
|
+
value: "opencode-vim.toggle",
|
|
17
|
+
description: vimEnabled() ? "Turn off Vim key handling" : "Turn on Vim key handling",
|
|
18
|
+
category: "Vim",
|
|
19
|
+
slash: { name: "vim" },
|
|
20
|
+
onSelect() {
|
|
21
|
+
const next = !vimEnabled()
|
|
22
|
+
setVimEnabled(next)
|
|
23
|
+
api.kv.set(vimEnabledKey, next)
|
|
24
|
+
api.ui.toast({ variant: "info", message: `Vim mode ${next ? "enabled" : "disabled"}` })
|
|
25
|
+
},
|
|
26
|
+
}])
|
|
27
|
+
|
|
10
28
|
if (readAutoUpdate(options)) {
|
|
11
29
|
let timer: Timer | undefined
|
|
12
30
|
api.lifecycle.onDispose(() => {
|
|
@@ -29,7 +47,7 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
29
47
|
|
|
30
48
|
const modules: PromptModule[] = []
|
|
31
49
|
if (hasSnippetsPlugin(api)) modules.push(createSnippetsModule())
|
|
32
|
-
modules.push(createVimModule(options))
|
|
50
|
+
modules.push(createVimModule(options, vimEnabled))
|
|
33
51
|
moduleCache.set(key, modules)
|
|
34
52
|
return modules
|
|
35
53
|
}
|