Skip to content

Commit 4d4786d

Browse files
Fix create affordance for trailing-slash directory paths
- Avoid offering Create & Add while directory browse results are pending - Preserve existing directory detection when the query ends with `/` - Add a regression test for existing directories with trailing slashes
1 parent 20e6a35 commit 4d4786d

2 files changed

Lines changed: 101 additions & 8 deletions

File tree

‎apps/web/src/components/ChatView.browser.tsx‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,6 +4460,98 @@ describe("ChatView timeline estimator parity (full app)", () => {
44604460
}
44614461
});
44624462

4463+
it("does not show create affordances for an existing directory with a trailing slash", async () => {
4464+
const mounted = await mountChatView({
4465+
viewport: DEFAULT_VIEWPORT,
4466+
snapshot: createSnapshotForTargetUser({
4467+
targetMessageId: "msg-user-command-palette-existing-trailing-directory" as MessageId,
4468+
targetText: "command palette existing trailing directory",
4469+
}),
4470+
resolveRpc: (body) => {
4471+
if (body._tag === WS_METHODS.filesystemBrowse) {
4472+
if (body.partialPath === "~/Development/codex/") {
4473+
return {
4474+
parentPath: "~/Development/codex/",
4475+
entries: [{ name: "Codex.app", fullPath: "~/Development/codex/Codex.app" }],
4476+
};
4477+
}
4478+
4479+
return {
4480+
parentPath: "~/",
4481+
entries: [{ name: "Development", fullPath: "~/Development" }],
4482+
};
4483+
}
4484+
4485+
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
4486+
return {
4487+
sequence: fixture.snapshot.snapshotSequence + 1,
4488+
};
4489+
}
4490+
4491+
return undefined;
4492+
},
4493+
});
4494+
4495+
try {
4496+
await waitForServerConfigToApply();
4497+
const palette = page.getByTestId("command-palette");
4498+
await page.getByTestId("sidebar-add-project-trigger").click();
4499+
4500+
await expect.element(palette).toBeInTheDocument();
4501+
const browseInput = await waitForCommandPaletteInput(ADD_PROJECT_SUBMENU_PLACEHOLDER);
4502+
await page.getByPlaceholder(ADD_PROJECT_SUBMENU_PLACEHOLDER).fill("~/Development/codex/");
4503+
4504+
await vi.waitFor(
4505+
() => {
4506+
expect(
4507+
wsRequests.some(
4508+
(request) =>
4509+
request._tag === WS_METHODS.filesystemBrowse &&
4510+
request.partialPath === "~/Development/codex/",
4511+
),
4512+
).toBe(true);
4513+
},
4514+
{ timeout: 8_000, interval: 16 },
4515+
);
4516+
4517+
await expect
4518+
.element(palette.getByRole("button", { name: "Add (Enter)" }))
4519+
.toBeInTheDocument();
4520+
await expect
4521+
.element(palette.getByRole("button", { name: "Create & Add (Enter)" }))
4522+
.not.toBeInTheDocument();
4523+
4524+
await dispatchInputKey(browseInput, { key: "Enter" });
4525+
4526+
await vi.waitFor(
4527+
() => {
4528+
const dispatchRequest = wsRequests.find(
4529+
(request) =>
4530+
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
4531+
request.type === "project.create",
4532+
) as
4533+
| {
4534+
_tag: string;
4535+
type?: string;
4536+
workspaceRoot?: string;
4537+
title?: string;
4538+
}
4539+
| undefined;
4540+
4541+
expect(dispatchRequest).toMatchObject({
4542+
_tag: ORCHESTRATION_WS_METHODS.dispatchCommand,
4543+
type: "project.create",
4544+
workspaceRoot: "~/Development/codex",
4545+
title: "codex",
4546+
});
4547+
},
4548+
{ timeout: 8_000, interval: 16 },
4549+
);
4550+
} finally {
4551+
await mounted.cleanup();
4552+
}
4553+
});
4554+
44634555
it("selects an environment before browsing when multiple environments are available", async () => {
44644556
const remoteBrowseMock = vi.fn(async ({ partialPath }: { partialPath: string }) => {
44654557
if (partialPath === "~/workspaces/") {

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function OpenCommandPaletteDialog() {
351351
[browseEnvironmentId, currentProjectCwdForBrowse],
352352
);
353353

354-
const { data: browseResult } = useQuery({
354+
const { data: browseResult, isPending: isBrowsePending } = useQuery({
355355
queryKey: [
356356
"filesystemBrowse",
357357
browseEnvironmentId,
@@ -858,11 +858,10 @@ function OpenCommandPaletteDialog() {
858858
const canSubmitBrowsePath = isBrowsing && !relativePathNeedsActiveProject;
859859
const willCreateProjectPath =
860860
canSubmitBrowsePath &&
861+
!isBrowsePending &&
861862
query.trim().length > 0 &&
862863
!hasHighlightedBrowseItem &&
863-
(hasTrailingPathSeparator(query)
864-
? (browseResult?.parentPath ?? "") !== query.trim()
865-
: exactBrowseEntry === null);
864+
(hasTrailingPathSeparator(query) ? !browseResult : exactBrowseEntry === null);
866865
const useMetaForMod = isMacPlatform(navigator.platform);
867866
const submitModifierLabel = useMetaForMod ? "\u2318" : "Ctrl";
868867
const submitActionLabel = willCreateProjectPath ? "Create & Add" : "Add";
@@ -1025,7 +1024,10 @@ function OpenCommandPaletteDialog() {
10251024
variant="outline"
10261025
size="xs"
10271026
tabIndex={-1}
1028-
className="absolute end-2.5 top-1/2 gap-1.5 -translate-y-1/2"
1027+
className={cn(
1028+
"absolute end-2.5 top-1/2 pe-1 ps-2 -translate-y-1/2",
1029+
hasHighlightedBrowseItem ? "gap-1" : "gap-1.5",
1030+
)}
10291031
aria-label={`${submitActionLabel} (${addShortcutLabel})`}
10301032
disabled={relativePathNeedsActiveProject}
10311033
onMouseDown={(event) => {
@@ -1040,9 +1042,8 @@ function OpenCommandPaletteDialog() {
10401042
title={`${submitActionLabel} (${addShortcutLabel})`}
10411043
>
10421044
<span>{submitActionLabel}</span>
1043-
<KbdGroup className="pointer-events-none items-center gap-1">
1044-
{hasHighlightedBrowseItem ? <Kbd>{submitModifierLabel}</Kbd> : null}
1045-
<Kbd>Enter</Kbd>
1045+
<KbdGroup className="pointer-events-none -me-0.5 items-center gap-1">
1046+
<Kbd>{hasHighlightedBrowseItem ? `${submitModifierLabel} Enter` : "Enter"}</Kbd>
10461047
</KbdGroup>
10471048
</Button>
10481049
) : null}

0 commit comments

Comments
 (0)