fix(tui): restore prompt from undo autocomplete

This commit is contained in:
Aiden Cline
2026-07-05 23:38:43 -05:00
parent cdb8fc9960
commit 4bd1ecb232
3 changed files with 7 additions and 6 deletions
+1 -5
View File
@@ -399,13 +399,9 @@ export function Session() {
title: "Undo previous message",
value: "session.undo",
category: "Session",
slash: { name: "undo", aliases: ["revert"] },
slash: { name: "undo" },
run: () => {
void (async () => {
const current = prompt?.current
if (current && current.parts.length === 0 && ["/undo", "/revert"].includes(current.input.trim())) {
prompt?.reset()
}
const boundary = session()?.revert?.messageID
const list = messages()
let target: SessionMessageUser | undefined
+2 -1
View File
@@ -2,7 +2,8 @@ import type { SessionMessageUser } from "@opencode-ai/sdk/v2"
import type { PromptInfo } from "../prompt/history"
export function revertedPrompt(current: PromptInfo, message: SessionMessageUser): PromptInfo | undefined {
if (current.input || current.parts.length) return
const input = current.input.trim()
if (current.parts.length || (input && !"/undo".startsWith(input))) return
return {
input: message.text,
@@ -43,6 +43,10 @@ describe("reverted prompt", () => {
})
})
test.each(["/", "/u", "/un", "/und", "/undo", " /undo "])("replaces the undo autocomplete query %p", (input) => {
expect(revertedPrompt({ input, parts: [] }, message)?.input).toBe("Fix the tests")
})
test("preserves an existing text draft", () => {
expect(revertedPrompt({ input: "Keep this", parts: [] }, message)).toBeUndefined()
})