Skip to content
Open
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
27 changes: 27 additions & 0 deletions packages/cli/src/ui/hooks/useCommandCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,33 @@ describe('useCommandCompletion', () => {
);
});
});

it('should enable AT completion when @ appears after a slash command', async () => {
// Regression test for #2518: typing @ after a custom slash command
// should trigger file search, not remain in SLASH mode.
const text = '/qc:create-issue @readme';

renderHook(() =>
useCommandCompletion(
useTextBufferForTest(text),
testDirs,
testRootDir,
[],
mockCommandContext,
false,
mockConfig,
),
);

await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
expect.objectContaining({
enabled: true,
pattern: 'readme',
}),
);
});
});
});

describe('Navigation', () => {
Expand Down
20 changes: 12 additions & 8 deletions packages/cli/src/ui/hooks/useCommandCompletion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,10 @@ export function useCommandCompletion(
const { completionMode, query, completionStart, completionEnd } =
useMemo(() => {
const currentLine = buffer.lines[cursorRow] || '';
if (cursorRow === 0 && isSlashCommand(currentLine.trim())) {
return {
completionMode: CompletionMode.SLASH,
query: currentLine,
completionStart: 0,
completionEnd: currentLine.length,
};
}

// Check for @ file reference first — it takes priority over slash
// command completion so that typing `@` after a slash command on the
// same line still triggers file search (see #2518).
const codePoints = toCodePoints(currentLine);
for (let i = cursorCol - 1; i >= 0; i--) {
const char = codePoints[i];
Expand Down Expand Up @@ -121,6 +116,15 @@ export function useCommandCompletion(
}
}

if (cursorRow === 0 && isSlashCommand(currentLine.trim())) {
return {
completionMode: CompletionMode.SLASH,
query: currentLine,
completionStart: 0,
completionEnd: currentLine.length,
};
}

return {
completionMode: CompletionMode.IDLE,
query: null,
Expand Down
Loading