fix(tui): complete Mini exit aliases (#50388)

Co-authored-by: Simon Klee <hello@simonklee.dk>
This commit is contained in:
xin zhuang
2026-09-22 01:04:58 +08:00
committed by GitHub
parent 3f0118022b
commit b8aa08f260
3 changed files with 11 additions and 10 deletions
+6 -7
View File
@@ -41,6 +41,7 @@ import {
createPromptHistory,
displayCharAt,
displaySlice,
EXIT_COMMANDS,
isExitCommand,
isCompactCommand,
mentionTriggerIndex,
@@ -531,7 +532,9 @@ export function createPromptState(input: PromptInput): PromptState {
display: "/compact",
description: "compact older session context to free space",
} satisfies SlashOption,
{ kind: "slash", name: "exit", display: "/exit", description: "close OpenCode" } satisfies SlashOption,
...EXIT_COMMANDS.map(
(name) => ({ kind: "slash", name, display: `/${name}`, description: "close OpenCode" }) satisfies SlashOption,
),
]
const hidden = new Set(builtins.map((item) => item.name))
return [
@@ -566,11 +569,7 @@ export function createPromptState(input: PromptInput): PromptState {
return fuzzysort
.go(next, mixed, {
keys: [
(item) => (item.kind === "mention" ? item.value : item.name).trimEnd(),
"display",
"description",
],
keys: [(item) => (item.kind === "mention" ? item.value : item.name).trimEnd(), "display", "description"],
})
.map((item) => item.obj)
})
@@ -1054,7 +1053,7 @@ export function createPromptState(input: PromptInput): PromptState {
const cursor = area.cursorOffset
const head = parseSlashHead(area.plainText)
const local = !shell() && (next.name === "new" || next.name === "exit")
const local = !shell() && (next.name === "new" || isExitCommand(`/${next.name}`))
const separator = !shell() && !local && head && /\s/.test(area.plainText[head.end] ?? "") ? "" : " "
const text = `/${next.name}${separator}`
+3 -1
View File
@@ -44,9 +44,11 @@ export function promptSame(a: RunPrompt, b: RunPrompt): boolean {
)
}
export const EXIT_COMMANDS = ["exit", "quit", "q"]
export function isExitCommand(input: string): boolean {
const text = input.trim().toLowerCase()
return text === "/exit" || text === "/quit" || text === ":q"
return text === ":q" || EXIT_COMMANDS.some((name) => text === `/${name}`)
}
export function isNewCommand(input: string): boolean {
+2 -2
View File
@@ -61,7 +61,7 @@ describe("run runtime queue", () => {
await task
})
test("treats /exit as a close command", async () => {
test.each(["/exit", "/quit", "/q", ":q"])("treats %s as a close command", async (text) => {
const ui = createFooterApiFixture()
let calls = 0
@@ -72,7 +72,7 @@ describe("run runtime queue", () => {
},
})
ui.submit("/exit")
ui.submit(text)
await task
expect(calls).toBe(0)