mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-23 02:36:57 -04:00
fix(tui): restore prompt from undo autocomplete
This commit is contained in:
@@ -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,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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user