فهرست منبع

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

Kit Langton 3 ماه پیش
والد
کامیت
e8ce5df414
1فایلهای تغییر یافته به همراه19 افزوده شده و 7 حذف شده
  1. 19 7
      packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

+ 19 - 7
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

@@ -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