fix(tui): retain cleared prompt drafts (#26258)
This commit is contained in:
@@ -94,6 +94,8 @@ const money = new Intl.NumberFormat("en-US", {
|
|||||||
currency: "USD",
|
currency: "USD",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const DRAFT_RETENTION_MIN_CHARS = 20
|
||||||
|
|
||||||
function randomIndex(count: number) {
|
function randomIndex(count: number) {
|
||||||
if (count <= 0) return 0
|
if (count <= 0) return 0
|
||||||
return Math.floor(Math.random() * count)
|
return Math.floor(Math.random() * count)
|
||||||
@@ -412,13 +414,7 @@ export function Prompt(props: PromptProps) {
|
|||||||
category: "Prompt",
|
category: "Prompt",
|
||||||
hidden: true,
|
hidden: true,
|
||||||
run: () => {
|
run: () => {
|
||||||
input.clear()
|
clearPrompt()
|
||||||
input.extmarks.clear()
|
|
||||||
setStore("prompt", {
|
|
||||||
input: "",
|
|
||||||
parts: [],
|
|
||||||
})
|
|
||||||
setStore("extmarkToPartIndex", new Map())
|
|
||||||
dialog.clear()
|
dialog.clear()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1356,6 +1352,22 @@ export function Prompt(props: PromptProps) {
|
|||||||
return
|
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(() => {
|
const highlight = createMemo(() => {
|
||||||
if (leader()) return theme.border
|
if (leader()) return theme.border
|
||||||
if (store.mode === "shell") return theme.primary
|
if (store.mode === "shell") return theme.primary
|
||||||
|
|||||||
Reference in New Issue
Block a user