From 60420e52dbeb8a2c3b5ec961a3c3e6ec0f648455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Medrano=20Llamas?= <45878745+rmedranollamas@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:10:23 +0200 Subject: [PATCH] feat: Do not add trailing space on directory autocomplete (#11227) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- .../src/ui/hooks/useCommandCompletion.test.ts | 62 +++++++++++++++++++ .../cli/src/ui/hooks/useCommandCompletion.tsx | 6 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.test.ts b/packages/cli/src/ui/hooks/useCommandCompletion.test.ts index 5274d3d560..f9fbeedc3d 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.test.ts +++ b/packages/cli/src/ui/hooks/useCommandCompletion.test.ts @@ -515,6 +515,68 @@ describe('useCommandCompletion', () => { '@src/file1.txt is a good file', ); }); + + it('should complete a directory path ending with / without a trailing space', async () => { + setupMocks({ + atSuggestions: [{ label: 'src/components/', value: 'src/components/' }], + }); + + const { result } = renderHook(() => { + const textBuffer = useTextBufferForTest('@src/comp'); + const completion = useCommandCompletion( + textBuffer, + testDirs, + testRootDir, + [], + mockCommandContext, + false, + mockConfig, + ); + return { ...completion, textBuffer }; + }); + + await waitFor(() => { + expect(result.current.suggestions.length).toBe(1); + }); + + act(() => { + result.current.handleAutocomplete(0); + }); + + expect(result.current.textBuffer.text).toBe('@src/components/'); + }); + + it('should complete a directory path ending with \\ without a trailing space', async () => { + setupMocks({ + atSuggestions: [ + { label: 'src\\components\\', value: 'src\\components\\' }, + ], + }); + + const { result } = renderHook(() => { + const textBuffer = useTextBufferForTest('@src\\comp'); + const completion = useCommandCompletion( + textBuffer, + testDirs, + testRootDir, + [], + mockCommandContext, + false, + mockConfig, + ); + return { ...completion, textBuffer }; + }); + + await waitFor(() => { + expect(result.current.suggestions.length).toBe(1); + }); + + act(() => { + result.current.handleAutocomplete(0); + }); + + expect(result.current.textBuffer.text).toBe('@src\\components\\'); + }); }); describe('prompt completion filtering', () => { diff --git a/packages/cli/src/ui/hooks/useCommandCompletion.tsx b/packages/cli/src/ui/hooks/useCommandCompletion.tsx index 398e3daafc..b55eb89724 100644 --- a/packages/cli/src/ui/hooks/useCommandCompletion.tsx +++ b/packages/cli/src/ui/hooks/useCommandCompletion.tsx @@ -230,7 +230,11 @@ export function useCommandCompletion( const lineCodePoints = toCodePoints(buffer.lines[cursorRow] || ''); const charAfterCompletion = lineCodePoints[end]; - if (charAfterCompletion !== ' ') { + if ( + charAfterCompletion !== ' ' && + !suggestionText.endsWith('/') && + !suggestionText.endsWith('\\') + ) { suggestionText += ' '; }