Skip to content

Commit 03c9b61

Browse files
authored
Merge pull request #129 from hqwlkj/main
fix(prompt-buffer): 修正 getCurrentSlashToken 函数逻辑
2 parents d3c991c + 602d886 commit 03c9b61

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)