Skip to content

Commit 1baad75

Browse files
committed
fix(prompt-buffer): 修正 getCurrentSlashToken 函数逻辑
- 优化判断逻辑,只有当文本以斜杠开头时才返回完整文本 - 移除按行处理逻辑,直接返回整个文本 - 修改测试用例以匹配新的行为 - 确保多行文本中不以斜杠开头时返回 null
1 parent 98c503c commit 1baad75

2 files changed

Lines changed: 6 additions & 16 deletions

File tree

src/tests/prompt-buffer.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ test("getCurrentSlashToken returns the slash word at the cursor", () => {
106106
assert.equal(getCurrentSlashToken(buffer), "/skill");
107107
});
108108

109-
test("getCurrentSlashToken returns null when token contains whitespace", () => {
109+
test("getCurrentSlashToken returns full text when it starts with /", () => {
110110
const buffer = { text: "/skill foo", cursor: 10 };
111-
assert.equal(getCurrentSlashToken(buffer), null);
111+
assert.equal(getCurrentSlashToken(buffer), "/skill foo");
112112
});
113113

114-
test("getCurrentSlashToken supports slash on a new line", () => {
114+
test("getCurrentSlashToken returns null when text starts on a new line with /", () => {
115115
const buffer = { text: "do this\n/n", cursor: 10 };
116-
assert.equal(getCurrentSlashToken(buffer), "/n");
116+
assert.equal(getCurrentSlashToken(buffer), null);
117117
});
118118

119119
test("getCurrentSlashToken returns null when no slash prefix", () => {

src/ui/core/prompt-buffer.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,10 @@ export function isEmpty(state: PromptBufferState): boolean {
155155

156156
export function getCurrentSlashToken(state: PromptBufferState): string | null {
157157
const text = state.text;
158-
if (text.length === 0) {
158+
if (text.length === 0 || !text.startsWith("/")) {
159159
return null;
160160
}
161-
const beforeCursor = text.slice(0, state.cursor);
162-
const lastNewline = beforeCursor.lastIndexOf("\n");
163-
const lineStart = lastNewline + 1;
164-
const line = beforeCursor.slice(lineStart);
165-
if (!line.startsWith("/")) {
166-
return null;
167-
}
168-
if (/\s/.test(line)) {
169-
return null;
170-
}
171-
return line;
161+
return text;
172162
}
173163

174164
/**

0 commit comments

Comments
 (0)