From 6352bcf3c9ca733b7c93cf220e410ef201318c31 Mon Sep 17 00:00:00 2001 From: tlh38 Date: Sat, 7 Feb 2026 01:17:42 -0500 Subject: [PATCH] feat(tui): clear input on double input_clear with visual indicator --- .../cli/cmd/tui/component/prompt/index.tsx | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index cefef208de4..487a7186055 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -60,6 +60,7 @@ export function Prompt(props: PromptProps) { let input: TextareaRenderable let anchor: BoxRenderable let autocomplete: AutocompleteRef + let clearInputTimer: ReturnType | undefined const keybind = useKeybind() const local = useLocal() @@ -124,6 +125,7 @@ export function Prompt(props: PromptProps) { extmarkToPartIndex: Map interrupt: number placeholder: number + clearCount: number }>({ placeholder: Math.floor(Math.random() * PLACEHOLDERS.length), prompt: { @@ -133,6 +135,7 @@ export function Prompt(props: PromptProps) { mode: "normal", extmarkToPartIndex: new Map(), interrupt: 0, + clearCount: 0, }) createEffect( @@ -166,6 +169,18 @@ export function Prompt(props: PromptProps) { } }) + function scheduleClearReset() { + if (clearInputTimer) clearTimeout(clearInputTimer) + clearInputTimer = setTimeout(() => { + setStore("clearCount", 0) + clearInputTimer = undefined + }, 2000) + } + + onCleanup(() => { + if (clearInputTimer) clearTimeout(clearInputTimer) + }) + command.register(() => { return [ { @@ -852,14 +867,21 @@ export function Prompt(props: PromptProps) { // If no image, let the default paste behavior continue } if (keybind.match("input_clear", e) && store.prompt.input !== "") { - input.clear() - input.extmarks.clear() - setStore("prompt", { - input: "", - parts: [], - }) - setStore("extmarkToPartIndex", new Map()) - return + setStore("clearCount", store.clearCount + 1) + if (store.clearCount >= 2) { + if (clearInputTimer) clearTimeout(clearInputTimer) + clearInputTimer = undefined + input.clear() + input.extmarks.clear() + setStore("prompt", { + input: "", + parts: [], + }) + setStore("extmarkToPartIndex", new Map()) + setStore("clearCount", 0) + return + } + scheduleClearReset() } if (keybind.match("app_exit", e)) { if (store.prompt.input === "") { @@ -1012,6 +1034,13 @@ export function Prompt(props: PromptProps) { + + 0}> + + {keybind.print("input_clear")} again to clear + + +