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
29 changes: 28 additions & 1 deletion packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { usePromptStash } from "./stash"
import { DialogStash } from "../dialog-stash"
import { type AutocompleteRef, Autocomplete } from "./autocomplete"
import { useCommandDialog } from "../dialog-command"
import { useRenderer } from "@opentui/solid"
import { useRenderer, useKeyboard } from "@opentui/solid"
import { Editor } from "@tui/util/editor"
import { useExit } from "../../context/exit"
import { Clipboard } from "../../util/clipboard"
Expand Down Expand Up @@ -646,6 +646,33 @@ export function Prompt(props: PromptProps) {
}
const exit = useExit()

let lastEscTime = 0
const DOUBLE_ESC_THRESHOLD = 300

// Global keyboard handler for double-ESC to clear input
useKeyboard((evt) => {
if (props.disabled) return
if (!input?.focused) return
if (evt.name !== "escape") return
if (store.prompt.input === "") return
if (dialog.stack.length > 0) return

const now = Date.now()
if (now - lastEscTime < DOUBLE_ESC_THRESHOLD) {
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
lastEscTime = 0
evt.preventDefault()
return
}
lastEscTime = now
})

function pasteText(text: string, virtualText: string) {
const currentOffset = input.visualCursor.offset
const extmarkStart = currentOffset
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/content/docs/keybinds.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ The OpenCode desktop app prompt input supports common Readline/Emacs-style short
| `alt+d` | Kill next word |
| `ctrl+t` | Transpose characters |
| `ctrl+g` | Cancel popovers / abort running response |
| `esc esc`| Clear input field (double press) |

---

Expand Down
Loading