fix(host): create folders with the entered name untrimmed

Same contract as the path editor: trim only rejects an all-whitespace
draft, and the Host receives the original spelling — the backend accepts
any non-blank single segment verbatim, so trimming here would create and
select a different sibling.
This commit is contained in:
creatixchu
2026-07-29 05:59:51 +08:00
parent 723bb9057c
commit 463893947b
2 changed files with 16 additions and 2 deletions

View File

@@ -211,8 +211,11 @@ export function DirectoryBrowser({ open, listDirectory, createDirectory, onOpen,
const confirmCreate = (): void => {
/* v8 ignore next -- reentry fence: the nested dialog only renders with a target and disables while creating. */
if (targetPath === null || folderDraft === null || creatingFolder) return
const name = folderDraft.trim()
if (name === '') return
// Trim only rejects an all-whitespace draft; the Host gets the original
// spelling — the backend accepts any non-blank single segment verbatim,
// and trimming here would create (and select) a different sibling.
const name = folderDraft
if (name.trim() === '') return
setCreatingFolder(true)
setCreateError(null)
const generation = openGeneration.current

View File

@@ -542,6 +542,17 @@ describe('DirectoryBrowser', () => {
expect(screen.getByText('Documents')).toBeTruthy()
})
it('passes the folder name to the Host untrimmed (trim only gates blank drafts)', async () => {
const b = mount()
await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })
fireEvent.click(screen.getByRole('button', { name: 'browser.newFolder' }))
const input = screen.getByLabelText('browser.folderName')
fireEvent.change(input, { target: { value: 'project ' } })
fireEvent.keyDown(input, { key: 'Enter' })
// A trailing space may be the wanted spelling; trimming would create a sibling.
await waitFor(() => { expect(b.createDirectory).toHaveBeenCalledWith(HOME, 'project ') })
})
it('creates a folder through the nested dialog and lands with it selected', async () => {
const b = mount()
await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })