diff options
| author | Adam <[email protected]> | 2026-01-20 07:10:40 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2026-01-20 07:33:44 -0600 |
| commit | 340285575b510f4ab466fa80d0de1cf20b4e048a (patch) | |
| tree | 9587a21664547875d060258ad7ee7b3de0dba290 /packages/app/src/context | |
| parent | dd5b5f5482df86959f0ea90e20f86ca7a5e19b08 (diff) | |
| download | opencode-340285575b510f4ab466fa80d0de1cf20b4e048a.tar.gz opencode-340285575b510f4ab466fa80d0de1cf20b4e048a.zip | |
chore: cleanup
Diffstat (limited to 'packages/app/src/context')
| -rw-r--r-- | packages/app/src/context/command.tsx | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/packages/app/src/context/command.tsx b/packages/app/src/context/command.tsx index 7986e7509..1e71801bd 100644 --- a/packages/app/src/context/command.tsx +++ b/packages/app/src/context/command.tsx @@ -1,7 +1,9 @@ -import { createMemo, createSignal, onCleanup, onMount, type Accessor } from "solid-js" +import { createEffect, createMemo, createSignal, onCleanup, onMount, type Accessor } from "solid-js" +import { createStore } from "solid-js/store" import { createSimpleContext } from "@opencode-ai/ui/context" import { useDialog } from "@opencode-ai/ui/context/dialog" import { useSettings } from "@/context/settings" +import { Persist, persisted } from "@/utils/persist" const IS_MAC = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform) @@ -44,6 +46,14 @@ export interface CommandOption { onHighlight?: () => (() => void) | void } +export type CommandCatalogItem = { + title: string + description?: string + category?: string + keybind?: KeybindConfig + slash?: string +} + export function parseKeybind(config: string): Keybind[] { if (!config || config === "none") return [] @@ -148,6 +158,11 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex const [registrations, setRegistrations] = createSignal<Accessor<CommandOption[]>[]>([]) const [suspendCount, setSuspendCount] = createSignal(0) + const [catalog, setCatalog, _, catalogReady] = persisted( + Persist.global("command.catalog.v1"), + createStore<Record<string, CommandCatalogItem>>({}), + ) + const bind = (id: string, def: KeybindConfig | undefined) => { const custom = settings.keybinds.get(actionId(id)) const config = custom ?? def @@ -155,7 +170,7 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex return config } - const options = createMemo(() => { + const registered = createMemo(() => { const seen = new Set<string>() const all: CommandOption[] = [] @@ -167,7 +182,28 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex } } - const resolved = all.map((opt) => ({ + return all + }) + + createEffect(() => { + if (!catalogReady()) return + + for (const opt of registered()) { + const id = actionId(opt.id) + setCatalog(id, { + title: opt.title, + description: opt.description, + category: opt.category, + keybind: opt.keybind, + slash: opt.slash, + }) + } + }) + + const catalogOptions = createMemo(() => Object.entries(catalog).map(([id, meta]) => ({ id, ...meta }))) + + const options = createMemo(() => { + const resolved = registered().map((opt) => ({ ...opt, keybind: bind(opt.id, opt.keybind), })) @@ -246,15 +282,23 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex return formatKeybind(settings.keybinds.get(PALETTE_ID) ?? DEFAULT_PALETTE_KEYBIND) } - const option = options().find((x) => x.id === id || x.id === SUGGESTED_PREFIX + id) - if (!option?.keybind) return "" - return formatKeybind(option.keybind) + const base = actionId(id) + const option = options().find((x) => actionId(x.id) === base) + if (option?.keybind) return formatKeybind(option.keybind) + + const meta = catalog[base] + const config = bind(base, meta?.keybind) + if (!config) return "" + return formatKeybind(config) }, show: showPalette, keybinds(enabled: boolean) { setSuspendCount((count) => count + (enabled ? -1 : 1)) }, suspended, + get catalog() { + return catalogOptions() + }, get options() { return options() }, |
