GeezerVison is showing github.com — dialog prompt submit keybind + opentui event sink (#27945) · zheli/opencode@f97e115
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bun.lock +15-37Lines changed: 15 additions & 37 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 35 | 35 | "@types/cross-spawn": "6.0.6", | 36 | 36 | "@octokit/rest": "22.0.0", | 37 | 37 | "@hono/zod-validator": "0.4.2", | 38 | | - "@opentui/core": "0.2.11", | 39 | | - "@opentui/keymap": "0.2.11", | 40 | | - "@opentui/solid": "0.2.11", | | 38 | + "@opentui/core": "0.2.13", | | 39 | + "@opentui/keymap": "0.2.13", | | 40 | + "@opentui/solid": "0.2.13", | 41 | 41 | "ulid": "3.0.1", | 42 | 42 | "@kobalte/core": "0.13.11", | 43 | 43 | "@types/luxon": "3.7.1", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/config/keybind.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -188,6 +188,7 @@ export const Definitions = { | 188 | 188 | "dialog.select.home": keybind("home", "Move to first dialog item"), | 189 | 189 | "dialog.select.end": keybind("end", "Move to last dialog item"), | 190 | 190 | "dialog.select.submit": keybind("return", "Submit selected dialog item"), | | 191 | + "dialog.prompt.submit": keybind("return", "Submit dialog prompt"), | 191 | 192 | "dialog.mcp.toggle": keybind("space", "Toggle MCP in MCP dialog"), | 192 | 193 | "prompt.autocomplete.prev": keybind("up,ctrl+p", "Move to previous autocomplete item"), | 193 | 194 | "prompt.autocomplete.next": keybind("down,ctrl+n", "Move to next autocomplete item"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/ui/dialog-prompt.tsx +33-8Lines changed: 33 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { TextareaRenderable, TextAttributes } from "@opentui/core" | 2 | 2 | import { useTheme } from "../context/theme" | 3 | 3 | import { useDialog, type DialogContext } from "./dialog" | 4 | | -import { Show, createEffect, onMount, type JSX } from "solid-js" | | 4 | +import { Show, createEffect, createSignal, onMount, type JSX } from "solid-js" | 5 | 5 | import { Spinner } from "../component/spinner" | | 6 | +import { useTuiConfig } from "../context/tui-config" | | 7 | +import { useBindings, useCommandShortcut } from "../keymap" | 6 | 8 |
| 7 | 9 | export type DialogPromptProps = { | 8 | 10 | title: string | @@ -18,8 +20,32 @@ export type DialogPromptProps = { | 18 | 20 | export function DialogPrompt(props: DialogPromptProps) { | 19 | 21 | const dialog = useDialog() | 20 | 22 | const { theme } = useTheme() | | 23 | + const tuiConfig = useTuiConfig() | | 24 | + const submitShortcut = useCommandShortcut("dialog.prompt.submit") | | 25 | + const [textareaTarget, setTextareaTarget] = createSignal<TextareaRenderable>() | 21 | 26 | let textarea: TextareaRenderable | 22 | 27 |
| | 28 | + function confirm() { | | 29 | + if (props.busy) return | | 30 | + props.onConfirm?.(textarea.plainText) | | 31 | + } | | 32 | + | | 33 | + useBindings(() => ({ | | 34 | + target: textareaTarget, | | 35 | + enabled: textareaTarget() !== undefined && !props.busy, | | 36 | + // Dialog form semantics must win over the global managed textarea input layer. | | 37 | + priority: 1, | | 38 | + commands: [ | | 39 | + { | | 40 | + name: "dialog.prompt.submit", | | 41 | + title: "Submit dialog prompt", | | 42 | + category: "Dialog", | | 43 | + run: confirm, | | 44 | + }, | | 45 | + ], | | 46 | + bindings: tuiConfig.keybinds.gather("dialog.prompt", ["dialog.prompt.submit"]), | | 47 | + })) | | 48 | + | 23 | 49 | onMount(() => { | 24 | 50 | dialog.setSize("medium") | 25 | 51 | setTimeout(() => { | @@ -59,13 +85,10 @@ export function DialogPrompt(props: DialogPromptProps) { | 59 | 85 | <box gap={1}> | 60 | 86 | {props.description} | 61 | 87 | <textarea | 62 | | - onSubmit={() => { | 63 | | - if (props.busy) return | 64 | | - props.onConfirm?.(textarea.plainText) | 65 | | - }} | 66 | 88 | height={3} | 67 | 89 | ref={(val: TextareaRenderable) => { | 68 | 90 | textarea = val | | 91 | + setTextareaTarget(val) | 69 | 92 | }} | 70 | 93 | initialValue={props.value} | 71 | 94 | placeholder={props.placeholder ?? "Enter text"} | @@ -80,9 +103,11 @@ export function DialogPrompt(props: DialogPromptProps) { | 80 | 103 | </box> | 81 | 104 | <box paddingBottom={1} gap={1} flexDirection="row"> | 82 | 105 | <Show when={!props.busy} fallback={<text fg={theme.textMuted}>processing...</text>}> | 83 | | - <text fg={theme.text}> | 84 | | - enter <span style={{ fg: theme.textMuted }}>submit</span> | 85 | | - </text> | | 106 | + <Show when={submitShortcut()}> | | 107 | + <text fg={theme.text}> | | 108 | + {submitShortcut()} <span style={{ fg: theme.textMuted }}>submit</span> | | 109 | + </text> | | 110 | + </Show> | 86 | 111 | </Show> | 87 | 112 | </box> | 88 | 113 | </box> | |
|