fix(tui): retain cleared prompt drafts (#26258)

This commit is contained in:
Kit Langton
2026-05-07 22:08:29 -04:00
committed by GitHub
parent b8799be3c8
commit e8ce5df414

View File

@@ -94,6 +94,8 @@ const money = new Intl.NumberFormat("en-US", {
currency: "USD",
})
const DRAFT_RETENTION_MIN_CHARS = 20
function randomIndex(count: number) {
if (count <= 0) return 0
return Math.floor(Math.random() * count)
@@ -412,13 +414,7 @@ export function Prompt(props: PromptProps) {
category: "Prompt",
hidden: true,
run: () => {
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
clearPrompt()
dialog.clear()
},
},
@@ -1356,6 +1352,22 @@ export function Prompt(props: PromptProps) {
return
}
function clearPrompt() {
if (store.prompt.input.trim().length >= DRAFT_RETENTION_MIN_CHARS || store.prompt.parts.length > 0) {
history.append({
...store.prompt,
mode: store.mode,
})
}
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
}
const highlight = createMemo(() => {
if (leader()) return theme.border
if (store.mode === "shell") return theme.primary