Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions packages/opencode/src/cli/cmd/tui/component/dialog-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function init() {
const root = getOwner()
const [registrations, setRegistrations] = createSignal<Accessor<CommandOption[]>[]>([])
const [suspendCount, setSuspendCount] = createSignal(0)
const [inputSuspendCount, setInputSuspendCount] = createSignal(0)
const dialog = useDialog()
const keybind = useKeybind()
const lang = useLanguage()
Expand Down Expand Up @@ -80,16 +81,20 @@ function init() {
category: lang.t("tui.command.palette.suggested"),
})),
)
const suspended = () => suspendCount() > 0
const suspended = () => suspendCount() > 0 || inputSuspendCount() > 0
const fullySuspended = () => suspendCount() > 0
const inputSuspended = () => inputSuspendCount() > 0
const isTextEditingKey = (evt: Parameters<typeof keybind.match>[1]) =>
Object.keys(keybind.all).some(
(name) =>
(name.startsWith("input_") || name === "history_previous" || name === "history_next") &&
keybind.match(name, evt),
)
const isSuspendedInputKey = (evt: Parameters<typeof keybind.match>[1]) =>
evt.name === "tab" || evt.name === "escape"

useKeyboard((evt) => {
if (suspended()) return
if (fullySuspended()) return
if (dialog.stack.length > 0) return
if (evt.defaultPrevented) return
const textInputFocused = isEditBufferRenderable(renderer.currentFocusedRenderable)
Expand All @@ -98,6 +103,7 @@ function init() {
if (!isEnabled(option)) continue
if (textEditingKey && !option.keybind?.startsWith("input_")) continue
if (option.keybind && keybind.match(option.keybind, evt)) {
if (inputSuspended() && isSuspendedInputKey(evt)) return
evt.preventDefault()
option.onSelect?.(dialog)
return
Expand Down Expand Up @@ -131,10 +137,16 @@ function init() {
]
})
},
keybinds(enabled: boolean) {
setSuspendCount((count) => count + (enabled ? -1 : 1))
keybinds(enabled: boolean, mode: "all" | "input" = "all") {
const update = (count: number) => count + (enabled ? -1 : 1)
if (mode === "input") setInputSuspendCount(update)
else setSuspendCount(update)
},
suspended(mode?: "all" | "input") {
if (mode === "all") return fullySuspended()
if (mode === "input") return inputSuspended()
return suspended()
},
suspended,
show() {
dialog.replace(() => <DialogCommand options={visibleOptions()} suggestedOptions={suggestedOptions()} />)
},
Expand Down Expand Up @@ -184,7 +196,7 @@ export function CommandProvider(props: ParentProps) {
const keybind = useKeybind()

useKeyboard((evt) => {
if (value.suspended()) return
if (value.suspended("all")) return
if (dialog.stack.length > 0) return
if (evt.defaultPrevented) return
if (keybind.match("command_list", evt)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ export function Prompt(props: PromptProps) {
// session change, status leaving idle).
createEffect(() => {
if (!ghost()) return
command.keybinds(false)
onCleanup(() => command.keybinds(true))
command.keybinds(false, "input")
onCleanup(() => command.keybinds(true, "input"))
})

const usage = createMemo(() => {
Expand Down
Loading