mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-13 07:30:52 -07:00
fix(ui): restrict space-suppression logic to SLASH mode only
This commit is contained in:
@@ -582,6 +582,33 @@ describe('useCommandCompletion', () => {
|
||||
|
||||
expect(result.current.textBuffer.text).toBe('@src\\components\\');
|
||||
});
|
||||
|
||||
it('should ADD a space for AT completion even if name matches a command with an action', async () => {
|
||||
// Setup a mock where getCommandFromSuggestion WOULD return a command with an action
|
||||
// if it were in SLASH mode.
|
||||
setupMocks({
|
||||
atSuggestions: [{ label: 'memory', value: 'memory' }],
|
||||
slashCompletionRange: {
|
||||
completionStart: 0,
|
||||
completionEnd: 0,
|
||||
getCommandFromSuggestion: () =>
|
||||
({ action: vi.fn() }) as unknown as SlashCommand,
|
||||
},
|
||||
});
|
||||
|
||||
const { result } = renderCommandCompletionHook('@mem');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.suggestions.length).toBe(1);
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.handleAutocomplete(0);
|
||||
});
|
||||
|
||||
// Should have a space because it's AT mode, not SLASH mode
|
||||
expect(result.current.textBuffer.text).toBe('@memory ');
|
||||
});
|
||||
});
|
||||
|
||||
describe('prompt completion filtering', () => {
|
||||
|
||||
@@ -362,12 +362,16 @@ export function useCommandCompletion({
|
||||
const lineCodePoints = toCodePoints(buffer.lines[cursorRow] || '');
|
||||
const charAfterCompletion = lineCodePoints[end];
|
||||
|
||||
const command = slashCompletionRange.getCommandFromSuggestion(suggestion);
|
||||
// Don't add a space if the command has an action (can be executed)
|
||||
// and doesn't have a completion function (doesn't REQUIRE more arguments)
|
||||
const isExecutableCommand = !!(command && command.action);
|
||||
const requiresArguments = !!(command && command.completion);
|
||||
const shouldAddSpace = !isExecutableCommand || requiresArguments;
|
||||
let shouldAddSpace = true;
|
||||
if (completionMode === CompletionMode.SLASH) {
|
||||
const command =
|
||||
slashCompletionRange.getCommandFromSuggestion(suggestion);
|
||||
// Don't add a space if the command has an action (can be executed)
|
||||
// and doesn't have a completion function (doesn't REQUIRE more arguments)
|
||||
const isExecutableCommand = !!(command && command.action);
|
||||
const requiresArguments = !!(command && command.completion);
|
||||
shouldAddSpace = !isExecutableCommand || requiresArguments;
|
||||
}
|
||||
|
||||
if (
|
||||
charAfterCompletion !== ' ' &&
|
||||
|
||||
Reference in New Issue
Block a user