fix(tui): restore prompt from undo autocomplete
This commit is contained in:
parent
cdb8fc9960
commit
4bd1ecb232
3 changed files with 7 additions and 6 deletions
|
|
@ -399,13 +399,9 @@ export function Session() {
|
||||||
title: "Undo previous message",
|
title: "Undo previous message",
|
||||||
value: "session.undo",
|
value: "session.undo",
|
||||||
category: "Session",
|
category: "Session",
|
||||||
slash: { name: "undo", aliases: ["revert"] },
|
slash: { name: "undo" },
|
||||||
run: () => {
|
run: () => {
|
||||||
void (async () => {
|
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 boundary = session()?.revert?.messageID
|
||||||
const list = messages()
|
const list = messages()
|
||||||
let target: SessionMessageUser | undefined
|
let target: SessionMessageUser | undefined
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ import type { SessionMessageUser } from "@opencode-ai/sdk/v2"
|
||||||
import type { PromptInfo } from "../prompt/history"
|
import type { PromptInfo } from "../prompt/history"
|
||||||
|
|
||||||
export function revertedPrompt(current: PromptInfo, message: SessionMessageUser): PromptInfo | undefined {
|
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 {
|
return {
|
||||||
input: message.text,
|
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", () => {
|
test("preserves an existing text draft", () => {
|
||||||
expect(revertedPrompt({ input: "Keep this", parts: [] }, message)).toBeUndefined()
|
expect(revertedPrompt({ input: "Keep this", parts: [] }, message)).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue