From 723bb9057cb840378e099a459796b210cf35996c Mon Sep 17 00:00:00 2001 From: creatixchu Date: Wed, 29 Jul 2026 05:49:18 +0800 Subject: [PATCH] fix(host): pass the entered path to the Host untrimmed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trim now only detects a blank draft; the original text navigates — a real directory name may end in whitespace, and trimming would list its sibling or adopt the wrong workspace. --- .../src/client/DirectoryBrowser.tsx | 6 ++++-- .../tests/directory-browser.spec.tsx | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/host/directory-picker-browse/src/client/DirectoryBrowser.tsx b/packages/host/directory-picker-browse/src/client/DirectoryBrowser.tsx index 1c50eb8167..db2231f384 100644 --- a/packages/host/directory-picker-browse/src/client/DirectoryBrowser.tsx +++ b/packages/host/directory-picker-browse/src/client/DirectoryBrowser.tsx @@ -347,8 +347,10 @@ export function DirectoryBrowser({ open, listDirectory, createDirectory, onOpen, onKeyDown={(event) => { if (event.key === 'Enter' && !composingRef.current) { event.preventDefault() - const target = pathDraft.trim() - if (target !== '') navigate(target) + // Trim only detects a blank draft; the Host gets the + // original text — a real directory name may end in + // whitespace, and trimming would list its sibling. + if (pathDraft.trim() !== '') navigate(pathDraft) } if (event.key === 'Escape') { event.stopPropagation() diff --git a/packages/host/directory-picker-browse/tests/directory-browser.spec.tsx b/packages/host/directory-picker-browse/tests/directory-browser.spec.tsx index 5221e627f8..dd7b7c0ae2 100644 --- a/packages/host/directory-picker-browse/tests/directory-browser.spec.tsx +++ b/packages/host/directory-picker-browse/tests/directory-browser.spec.tsx @@ -198,6 +198,18 @@ describe('DirectoryBrowser', () => { expect(listDirectory).toHaveBeenLastCalledWith(undefined) }) + it('passes the entered path to the Host untrimmed (trim only gates blank drafts)', async () => { + const listDirectory = vi.fn(async (path?: string) => listingFor(path)) + mount({ listDirectory }) + await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() }) + fireEvent.click(screen.getByRole('button', { name: 'browser.editPath' })) + const input = screen.getByLabelText('browser.editPath') + fireEvent.change(input, { target: { value: `${DOCS} ` } }) + fireEvent.keyDown(input, { key: 'Enter' }) + // A trailing space may name a real directory; trimming would list its sibling. + await waitFor(() => { expect(listDirectory).toHaveBeenLastCalledWith(`${DOCS} `) }) + }) + it('surfaces an unreadable target as an alert and keeps the edit open for correction', async () => { mount() await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })