Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/tests/prompt-buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
14 changes: 2 additions & 12 deletions src/ui/core/prompt-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Loading