|
@@ -8,9 +8,9 @@ import {
|
|
|
import {
|
|
import {
|
|
|
KeymapProvider,
|
|
KeymapProvider,
|
|
|
reactiveMatcherFromSignal,
|
|
reactiveMatcherFromSignal,
|
|
|
- useBindings,
|
|
|
|
|
useKeymap,
|
|
useKeymap,
|
|
|
useKeymapSelector,
|
|
useKeymapSelector,
|
|
|
|
|
+ useBindings,
|
|
|
} from "@opentui/keymap/solid"
|
|
} from "@opentui/keymap/solid"
|
|
|
import type { Accessor } from "solid-js"
|
|
import type { Accessor } from "solid-js"
|
|
|
import type { TuiConfig } from "./config/tui"
|
|
import type { TuiConfig } from "./config/tui"
|
|
@@ -26,6 +26,28 @@ export { reactiveMatcherFromSignal, useBindings, useKeymapSelector }
|
|
|
|
|
|
|
|
export type OpenTuiKeymap = ReturnType<typeof useKeymap>
|
|
export type OpenTuiKeymap = ReturnType<typeof useKeymap>
|
|
|
|
|
|
|
|
|
|
+const KEY_ALIASES = {
|
|
|
|
|
+ enter: "return",
|
|
|
|
|
+ esc: "escape",
|
|
|
|
|
+} as const
|
|
|
|
|
+
|
|
|
|
|
+function expandKeyAliases(input: string) {
|
|
|
|
|
+ const result = Object.entries(KEY_ALIASES).reduce(
|
|
|
|
|
+ (acc, [alias, key]) => acc.replace(new RegExp(`(^|[+,\\s>])${alias}(?=$|[+,\\s<])`, "gi"), `$1${key}`),
|
|
|
|
|
+ input,
|
|
|
|
|
+ )
|
|
|
|
|
+ if (result === input) return
|
|
|
|
|
+ return result
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function registerKeyAliases(keymap: OpenTuiKeymap) {
|
|
|
|
|
+ return keymap.appendBindingExpander((ctx) => {
|
|
|
|
|
+ const key = expandKeyAliases(ctx.input)
|
|
|
|
|
+ if (!key) return
|
|
|
|
|
+ return [{ key, displays: ctx.displays }]
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const inputCommands = [
|
|
const inputCommands = [
|
|
|
"input.move.left",
|
|
"input.move.left",
|
|
|
"input.move.right",
|
|
"input.move.right",
|
|
@@ -98,8 +120,13 @@ export function formatKeyBindings(
|
|
|
return formatCommandBindingsExtra(bindings, formatOptions(config))
|
|
return formatCommandBindingsExtra(bindings, formatOptions(config))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function registerOpencodeKeymap(keymap: OpenTuiKeymap, renderer: CliRenderer, config: TuiConfig.Resolved) {
|
|
|
|
|
|
|
+export function registerOpencodeKeymap(
|
|
|
|
|
+ keymap: OpenTuiKeymap,
|
|
|
|
|
+ renderer: CliRenderer,
|
|
|
|
|
+ config: Pick<TuiConfig.Resolved, "keybinds" | "leader_timeout">,
|
|
|
|
|
+) {
|
|
|
const offCommaBindings = addons.registerCommaBindings(keymap)
|
|
const offCommaBindings = addons.registerCommaBindings(keymap)
|
|
|
|
|
+ const offAliasExpander = registerKeyAliases(keymap)
|
|
|
const offBaseLayout = addons.registerBaseLayoutFallback(keymap)
|
|
const offBaseLayout = addons.registerBaseLayoutFallback(keymap)
|
|
|
const offLeader = addons.registerTimedLeader(keymap, {
|
|
const offLeader = addons.registerTimedLeader(keymap, {
|
|
|
trigger: config.keybinds.get(LEADER_TOKEN),
|
|
trigger: config.keybinds.get(LEADER_TOKEN),
|
|
@@ -108,20 +135,17 @@ export function registerOpencodeKeymap(keymap: OpenTuiKeymap, renderer: CliRende
|
|
|
})
|
|
})
|
|
|
const offEscape = addons.registerEscapeClearsPendingSequence(keymap)
|
|
const offEscape = addons.registerEscapeClearsPendingSequence(keymap)
|
|
|
const offBackspace = addons.registerBackspacePopsPendingSequence(keymap)
|
|
const offBackspace = addons.registerBackspacePopsPendingSequence(keymap)
|
|
|
- const offInputCommands = addons.registerEditBufferCommands(keymap, renderer)
|
|
|
|
|
- const offInputSuspension = addons.registerTextareaMappingSuspension(keymap, renderer)
|
|
|
|
|
- const offInputBindings = keymap.registerLayer({
|
|
|
|
|
|
|
+ const offInputBindings = addons.registerManagedTextareaLayer(keymap, renderer, {
|
|
|
enabled: () => renderer.currentFocusedEditor !== null,
|
|
enabled: () => renderer.currentFocusedEditor !== null,
|
|
|
bindings: config.keybinds.gather("input", inputCommands),
|
|
bindings: config.keybinds.gather("input", inputCommands),
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
return () => {
|
|
return () => {
|
|
|
offInputBindings()
|
|
offInputBindings()
|
|
|
- offInputSuspension()
|
|
|
|
|
- offInputCommands()
|
|
|
|
|
offBackspace()
|
|
offBackspace()
|
|
|
offEscape()
|
|
offEscape()
|
|
|
offLeader()
|
|
offLeader()
|
|
|
|
|
+ offAliasExpander()
|
|
|
offBaseLayout()
|
|
offBaseLayout()
|
|
|
offCommaBindings()
|
|
offCommaBindings()
|
|
|
}
|
|
}
|