From b2ab4af157c67f1b753d0335cc0cc761a0bd127e Mon Sep 17 00:00:00 2001 From: herjarsa Date: Fri, 28 Aug 2026 17:50:34 +0200 Subject: [PATCH] fix(directory-explorer): gate Space toggle on browse position; reorder batch path Two blockers from the openchamber-bot review: 1. Space swallowed in the path input. The handler at handleKeyDown was calling preventDefault on every Space, turning paths with spaces into no-op strokes and toggling the highlighted row instead. Gate the toggle on hasTrailingPathSeparator (query) so Space is a literal character when the user is typing a path or filter and only acts as a selection toggle when they have navigated into a directory. 2. Batch path was unreachable when the filter had no exact match. With checkboxes ticked and a typed filter that has no exact match, shouldCreateTarget evaluated true and the primary action (Add selected) called createDirectory for the typed text instead of adding the selections. Move the batch branch above shouldCreateSelection so explicit selections always win over the single-target create path. Drop the trailing else-if (now unreachable) which also lost { asProject: true }. --- .../session/DirectoryExplorerDialog.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/ui/src/components/session/DirectoryExplorerDialog.tsx b/packages/ui/src/components/session/DirectoryExplorerDialog.tsx index 7433e788..594d95a7 100644 --- a/packages/ui/src/components/session/DirectoryExplorerDialog.tsx +++ b/packages/ui/src/components/session/DirectoryExplorerDialog.tsx @@ -482,9 +482,10 @@ export const DirectoryExplorerDialog: React.FC = ( gitIdentityId: selectedGitIdentity?.id ?? null, }); selectedTarget = result.path; - } else if (shouldCreateSelection) { - await opencodeClient.createDirectory(target, { asProject: true }); } else if (selectionToAdd.length > 0) { + // Batch path wins over single-target create: with checkboxes ticked, + // the user wants the selections added, not a fresh directory created + // for whatever happens to be typed in the filter. const added = addProjects(selectionToAdd); if (added.length === 0) { toast.error(t('directoryExplorerDialog.toast.failedToAddProject'), { @@ -495,8 +496,8 @@ export const DirectoryExplorerDialog: React.FC = ( setSelectedPaths([]); handleClose(); return; - } else if (shouldCreateTarget && normalizeDirectoryPath(target) === normalizeDirectoryPath(targetPath)) { - await opencodeClient.createDirectory(target); + } else if (shouldCreateSelection) { + await opencodeClient.createDirectory(target, { asProject: true }); } const project = await addProject(selectedTarget); if (!project) { @@ -576,9 +577,16 @@ export const DirectoryExplorerDialog: React.FC = ( return; } if (event.key === ' ') { - event.preventDefault(); - if (highlightedRow && highlightedRow.type === 'directory' && !highlightedRow.disabled) { - togglePathSelection(highlightedRow.path); + // Only treat Space as a selection toggle when the user is actively + // browsing a directory (trailing slash or no filter typing). When + // the input is in path-entry mode, Space is a literal character + // and must reach the input value. + if (hasTrailingPathSeparator(query)) { + event.preventDefault(); + if (highlightedRow && highlightedRow.type === 'directory' && !highlightedRow.disabled) { + togglePathSelection(highlightedRow.path); + } + return; } return; }