mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
fix(tui): complete Mini exit aliases (#50388)
Co-authored-by: Simon Klee <hello@simonklee.dk>
This commit is contained in:
@@ -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}`
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user