From 1baad75b14f74059fa4398799d9ce6a37e94df6e Mon Sep 17 00:00:00 2001 From: hcyang Date: Thu, 28 May 2026 17:34:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(prompt-buffer):=20=E4=BF=AE=E6=AD=A3=20getC?= =?UTF-8?q?urrentSlashToken=20=E5=87=BD=E6=95=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化判断逻辑,只有当文本以斜杠开头时才返回完整文本 - 移除按行处理逻辑,直接返回整个文本 - 修改测试用例以匹配新的行为 - 确保多行文本中不以斜杠开头时返回 null --- src/tests/prompt-buffer.test.ts | 8 ++++---- src/ui/core/prompt-buffer.ts | 14 ++------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/tests/prompt-buffer.test.ts b/src/tests/prompt-buffer.test.ts index 67ac23a..19537f7 100644 --- a/src/tests/prompt-buffer.test.ts +++ b/src/tests/prompt-buffer.test.ts @@ -106,14 +106,14 @@ test("getCurrentSlashToken returns the slash word at the cursor", () => { assert.equal(getCurrentSlashToken(buffer), "/skill"); }); -test("getCurrentSlashToken returns null when token contains whitespace", () => { +test("getCurrentSlashToken returns full text when it starts with /", () => { const buffer = { text: "/skill foo", cursor: 10 }; - assert.equal(getCurrentSlashToken(buffer), null); + assert.equal(getCurrentSlashToken(buffer), "/skill foo"); }); -test("getCurrentSlashToken supports slash on a new line", () => { +test("getCurrentSlashToken returns null when text starts on a new line with /", () => { const buffer = { text: "do this\n/n", cursor: 10 }; - assert.equal(getCurrentSlashToken(buffer), "/n"); + assert.equal(getCurrentSlashToken(buffer), null); }); test("getCurrentSlashToken returns null when no slash prefix", () => { diff --git a/src/ui/core/prompt-buffer.ts b/src/ui/core/prompt-buffer.ts index 3e0a710b..c324930 100644 --- a/src/ui/core/prompt-buffer.ts +++ b/src/ui/core/prompt-buffer.ts @@ -155,20 +155,10 @@ export function isEmpty(state: PromptBufferState): boolean { export function getCurrentSlashToken(state: PromptBufferState): string | null { const text = state.text; - if (text.length === 0) { + if (text.length === 0 || !text.startsWith("/")) { return null; } - const beforeCursor = text.slice(0, state.cursor); - const lastNewline = beforeCursor.lastIndexOf("\n"); - const lineStart = lastNewline + 1; - const line = beforeCursor.slice(lineStart); - if (!line.startsWith("/")) { - return null; - } - if (/\s/.test(line)) { - return null; - } - return line; + return text; } /**