fix(host): pass the entered path to the Host untrimmed
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.
This commit is contained in:
@@ -347,8 +347,10 @@ export function DirectoryBrowser({ open, listDirectory, createDirectory, onOpen,
|
|||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === 'Enter' && !composingRef.current) {
|
if (event.key === 'Enter' && !composingRef.current) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const target = pathDraft.trim()
|
// Trim only detects a blank draft; the Host gets the
|
||||||
if (target !== '') navigate(target)
|
// 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') {
|
if (event.key === 'Escape') {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|||||||
@@ -198,6 +198,18 @@ describe('DirectoryBrowser', () => {
|
|||||||
expect(listDirectory).toHaveBeenLastCalledWith(undefined)
|
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<HTMLInputElement>('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 () => {
|
it('surfaces an unreadable target as an alert and keeps the edit open for correction', async () => {
|
||||||
mount()
|
mount()
|
||||||
await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })
|
await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })
|
||||||
|
|||||||
Reference in New Issue
Block a user