Skip to content

Commit 5dc6d92

Browse files
Refine command palette project submission shortcuts
- Allow Enter or Mod+Enter to add browsed projects based on selection state - Show the active add shortcut in the palette UI and keep highlighted rows in sync
1 parent 0ddcb1a commit 5dc6d92

3 files changed

Lines changed: 316 additions & 13 deletions

File tree

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

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const PROJECT_KEY = scopedProjectKey(scopeProjectRef(LOCAL_ENVIRONMENT_ID, PROJE
7070
const NOW_ISO = "2026-03-04T12:00:00.000Z";
7171
const BASE_TIME_MS = Date.parse(NOW_ISO);
7272
const ATTACHMENT_SVG = "<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'></svg>";
73+
const ADD_PROJECT_SUBMENU_PLACEHOLDER = "Enter path (e.g. ~/projects/my-app)";
7374

7475
interface TestFixture {
7576
snapshot: OrchestrationReadModel;
@@ -1383,6 +1384,44 @@ async function waitForCommandPaletteShortcutLabel(): Promise<void> {
13831384
);
13841385
}
13851386

1387+
async function waitForCommandPaletteInput(placeholder: string): Promise<HTMLInputElement> {
1388+
return waitForElement(
1389+
() => document.querySelector(`input[placeholder="${placeholder}"]`) as HTMLInputElement | null,
1390+
`Command palette input with placeholder "${placeholder}" did not render.`,
1391+
);
1392+
}
1393+
1394+
function getCommandPaletteLegendEntries(): string[] {
1395+
const footer = document.querySelector('[data-slot="command-footer"]');
1396+
if (!footer) {
1397+
return [];
1398+
}
1399+
1400+
return Array.from(footer.querySelectorAll('[data-slot="kbd-group"]'))
1401+
.map((group) =>
1402+
Array.from(group.children)
1403+
.map((child) => child.textContent?.trim() ?? "")
1404+
.filter((value) => value.length > 0)
1405+
.join(" "),
1406+
)
1407+
.filter((value) => value.length > 0);
1408+
}
1409+
1410+
async function dispatchInputKey(
1411+
input: HTMLInputElement,
1412+
init: Pick<KeyboardEventInit, "key" | "metaKey" | "ctrlKey" | "shiftKey" | "altKey">,
1413+
): Promise<void> {
1414+
input.focus();
1415+
input.dispatchEvent(
1416+
new KeyboardEvent("keydown", {
1417+
bubbles: true,
1418+
cancelable: true,
1419+
...init,
1420+
}),
1421+
);
1422+
await waitForLayout();
1423+
}
1424+
13861425
async function mountChatView(options: {
13871426
viewport: ViewportSpec;
13881427
snapshot: OrchestrationReadModel;
@@ -4079,6 +4118,244 @@ describe("ChatView timeline estimator parity (full app)", () => {
40794118
}
40804119
});
40814120

4121+
it("adds a project from browse mode with Enter when no directory is highlighted", async () => {
4122+
const mounted = await mountChatView({
4123+
viewport: DEFAULT_VIEWPORT,
4124+
snapshot: createSnapshotForTargetUser({
4125+
targetMessageId: "msg-user-command-palette-add-project-enter" as MessageId,
4126+
targetText: "command palette add project enter",
4127+
}),
4128+
configureFixture: (nextFixture) => {
4129+
nextFixture.serverConfig = {
4130+
...nextFixture.serverConfig,
4131+
keybindings: [
4132+
{
4133+
command: "commandPalette.toggle",
4134+
shortcut: {
4135+
key: "k",
4136+
metaKey: false,
4137+
ctrlKey: false,
4138+
shiftKey: false,
4139+
altKey: false,
4140+
modKey: true,
4141+
},
4142+
whenAst: {
4143+
type: "not",
4144+
node: { type: "identifier", name: "terminalFocus" },
4145+
},
4146+
},
4147+
],
4148+
};
4149+
},
4150+
resolveRpc: (body) => {
4151+
if (body._tag === WS_METHODS.filesystemBrowse) {
4152+
if (body.partialPath === "~/Development/") {
4153+
return {
4154+
parentPath: "~/Development/",
4155+
entries: [
4156+
{ name: "alpha", fullPath: "~/Development/alpha" },
4157+
{ name: "beta", fullPath: "~/Development/beta" },
4158+
],
4159+
};
4160+
}
4161+
4162+
return {
4163+
parentPath: "~/",
4164+
entries: [{ name: "Development", fullPath: "~/Development" }],
4165+
};
4166+
}
4167+
4168+
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
4169+
return {
4170+
sequence: fixture.snapshot.snapshotSequence + 1,
4171+
};
4172+
}
4173+
4174+
return undefined;
4175+
},
4176+
});
4177+
4178+
try {
4179+
await waitForServerConfigToApply();
4180+
await waitForCommandPaletteShortcutLabel();
4181+
const palette = page.getByTestId("command-palette");
4182+
await openCommandPaletteFromTrigger();
4183+
4184+
await expect.element(palette).toBeInTheDocument();
4185+
await palette.getByText("Add project", { exact: true }).click();
4186+
4187+
const browseInput = await waitForCommandPaletteInput(ADD_PROJECT_SUBMENU_PLACEHOLDER);
4188+
await page.getByPlaceholder(ADD_PROJECT_SUBMENU_PLACEHOLDER).fill("~/Development/");
4189+
await expect.element(palette.getByText("alpha", { exact: true })).toBeInTheDocument();
4190+
4191+
await expect
4192+
.element(palette.getByRole("button", { name: "Add (Enter)" }))
4193+
.toBeInTheDocument();
4194+
4195+
await dispatchInputKey(browseInput, { key: "Enter" });
4196+
4197+
await vi.waitFor(
4198+
() => {
4199+
const dispatchRequest = wsRequests.find(
4200+
(request) =>
4201+
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
4202+
request.type === "project.create",
4203+
) as
4204+
| {
4205+
_tag: string;
4206+
type?: string;
4207+
workspaceRoot?: string;
4208+
title?: string;
4209+
}
4210+
| undefined;
4211+
4212+
expect(dispatchRequest).toMatchObject({
4213+
_tag: ORCHESTRATION_WS_METHODS.dispatchCommand,
4214+
type: "project.create",
4215+
workspaceRoot: "~/Development",
4216+
title: "Development",
4217+
});
4218+
},
4219+
{ timeout: 8_000, interval: 16 },
4220+
);
4221+
4222+
await waitForURL(
4223+
mounted.router,
4224+
(path) => UUID_ROUTE_RE.test(path),
4225+
"Route should have changed to a new draft thread after adding a project with Enter.",
4226+
);
4227+
} finally {
4228+
await mounted.cleanup();
4229+
}
4230+
});
4231+
4232+
it("adds a project from browse mode with Mod+Enter when a directory is highlighted", async () => {
4233+
const mounted = await mountChatView({
4234+
viewport: DEFAULT_VIEWPORT,
4235+
snapshot: createSnapshotForTargetUser({
4236+
targetMessageId: "msg-user-command-palette-add-project-mod-enter" as MessageId,
4237+
targetText: "command palette add project mod enter",
4238+
}),
4239+
configureFixture: (nextFixture) => {
4240+
nextFixture.serverConfig = {
4241+
...nextFixture.serverConfig,
4242+
keybindings: [
4243+
{
4244+
command: "commandPalette.toggle",
4245+
shortcut: {
4246+
key: "k",
4247+
metaKey: false,
4248+
ctrlKey: false,
4249+
shiftKey: false,
4250+
altKey: false,
4251+
modKey: true,
4252+
},
4253+
whenAst: {
4254+
type: "not",
4255+
node: { type: "identifier", name: "terminalFocus" },
4256+
},
4257+
},
4258+
],
4259+
};
4260+
},
4261+
resolveRpc: (body) => {
4262+
if (body._tag === WS_METHODS.filesystemBrowse) {
4263+
if (body.partialPath === "~/Development/") {
4264+
return {
4265+
parentPath: "~/Development/",
4266+
entries: [
4267+
{ name: "alpha", fullPath: "~/Development/alpha" },
4268+
{ name: "beta", fullPath: "~/Development/beta" },
4269+
],
4270+
};
4271+
}
4272+
4273+
return {
4274+
parentPath: "~/",
4275+
entries: [{ name: "Development", fullPath: "~/Development" }],
4276+
};
4277+
}
4278+
4279+
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
4280+
return {
4281+
sequence: fixture.snapshot.snapshotSequence + 1,
4282+
};
4283+
}
4284+
4285+
return undefined;
4286+
},
4287+
});
4288+
4289+
try {
4290+
await waitForServerConfigToApply();
4291+
await waitForCommandPaletteShortcutLabel();
4292+
const palette = page.getByTestId("command-palette");
4293+
await openCommandPaletteFromTrigger();
4294+
4295+
await expect.element(palette).toBeInTheDocument();
4296+
await palette.getByText("Add project", { exact: true }).click();
4297+
4298+
const browseInput = await waitForCommandPaletteInput(ADD_PROJECT_SUBMENU_PLACEHOLDER);
4299+
await page.getByPlaceholder(ADD_PROJECT_SUBMENU_PLACEHOLDER).fill("~/Development/");
4300+
await expect.element(palette.getByText("alpha", { exact: true })).toBeInTheDocument();
4301+
4302+
await dispatchInputKey(browseInput, { key: "ArrowDown" });
4303+
4304+
const addButtonLabel = isMacPlatform(navigator.platform)
4305+
? "Add (\u2318 Enter)"
4306+
: "Add (Ctrl Enter)";
4307+
await vi.waitFor(
4308+
() => {
4309+
const legendEntries = getCommandPaletteLegendEntries();
4310+
expect(legendEntries).toContain("Enter Select");
4311+
},
4312+
{ timeout: 8_000, interval: 16 },
4313+
);
4314+
await expect
4315+
.element(palette.getByRole("button", { name: addButtonLabel }))
4316+
.toBeInTheDocument();
4317+
4318+
await dispatchInputKey(browseInput, {
4319+
key: "Enter",
4320+
metaKey: isMacPlatform(navigator.platform),
4321+
ctrlKey: !isMacPlatform(navigator.platform),
4322+
});
4323+
4324+
await vi.waitFor(
4325+
() => {
4326+
const dispatchRequest = wsRequests.find(
4327+
(request) =>
4328+
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
4329+
request.type === "project.create",
4330+
) as
4331+
| {
4332+
_tag: string;
4333+
type?: string;
4334+
workspaceRoot?: string;
4335+
title?: string;
4336+
}
4337+
| undefined;
4338+
4339+
expect(dispatchRequest).toMatchObject({
4340+
_tag: ORCHESTRATION_WS_METHODS.dispatchCommand,
4341+
type: "project.create",
4342+
workspaceRoot: "~/Development",
4343+
title: "Development",
4344+
});
4345+
},
4346+
{ timeout: 8_000, interval: 16 },
4347+
);
4348+
4349+
await waitForURL(
4350+
mounted.router,
4351+
(path) => UUID_ROUTE_RE.test(path),
4352+
"Route should have changed to a new draft thread after adding a project with Mod+Enter.",
4353+
);
4354+
} finally {
4355+
await mounted.cleanup();
4356+
}
4357+
});
4358+
40824359
it("keeps project-context thread matches available when searching by project name", async () => {
40834360
const mounted = await mountChatView({
40844361
viewport: DEFAULT_VIEWPORT,

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
} from "../lib/projectPaths";
5656
import { isTerminalFocused } from "../lib/terminalFocus";
5757
import { getLatestThreadForProject } from "../lib/threadSort";
58-
import { cn, newCommandId, newProjectId } from "../lib/utils";
58+
import { cn, isMacPlatform, newCommandId, newProjectId } from "../lib/utils";
5959
import {
6060
selectProjectsAcrossEnvironments,
6161
selectSidebarThreadsAcrossEnvironments,
@@ -606,16 +606,26 @@ function OpenCommandPaletteDialog() {
606606

607607
const inputPlaceholder = getCommandPaletteInputPlaceholder(paletteMode);
608608
const isSubmenu = paletteMode === "submenu" || paletteMode === "submenu-browse";
609+
const hasHighlightedBrowseItem = highlightedItemValue?.startsWith("browse:") ?? false;
610+
const canSubmitBrowsePath = isBrowsing && !relativePathNeedsActiveProject;
611+
const useMetaForMod = isMacPlatform(navigator.platform);
612+
const submitModifierLabel = useMetaForMod ? "\u2318" : "Ctrl";
613+
const addShortcutLabel = hasHighlightedBrowseItem ? `${submitModifierLabel} Enter` : "Enter";
614+
615+
function isPrimaryModifierPressed(event: KeyboardEvent<HTMLInputElement>): boolean {
616+
return useMetaForMod ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
617+
}
609618

610619
function handleKeyDown(event: KeyboardEvent<HTMLInputElement>): void {
611-
if (
612-
isBrowsing &&
620+
const shouldSubmitBrowsePath =
621+
canSubmitBrowsePath &&
613622
event.key === "Enter" &&
614-
!highlightedItemValue?.startsWith("browse:") &&
615-
!relativePathNeedsActiveProject
616-
) {
623+
(!hasHighlightedBrowseItem || isPrimaryModifierPressed(event));
624+
625+
if (shouldSubmitBrowsePath) {
617626
event.preventDefault();
618627
void handleAddProject(resolvedAddProjectPath);
628+
return;
619629
}
620630

621631
if (event.key === "Backspace" && query === "" && isSubmenu) {
@@ -698,7 +708,8 @@ function OpenCommandPaletteDialog() {
698708
variant="outline"
699709
size="xs"
700710
tabIndex={-1}
701-
className="absolute end-2.5 top-1/2 -translate-y-1/2"
711+
className="absolute end-2.5 top-1/2 gap-1.5 -translate-y-1/2"
712+
aria-label={`Add (${addShortcutLabel})`}
702713
disabled={relativePathNeedsActiveProject}
703714
onMouseDown={(event) => {
704715
event.preventDefault();
@@ -709,14 +720,20 @@ function OpenCommandPaletteDialog() {
709720
}
710721
void handleAddProject(resolvedAddProjectPath);
711722
}}
723+
title={`Add (${addShortcutLabel})`}
712724
>
713-
Add
725+
<span>Add</span>
726+
<KbdGroup className="pointer-events-none items-center gap-1">
727+
{hasHighlightedBrowseItem ? <Kbd>{submitModifierLabel}</Kbd> : null}
728+
<Kbd>Enter</Kbd>
729+
</KbdGroup>
714730
</Button>
715731
) : null}
716732
</div>
717733
<CommandPanel className="max-h-[min(28rem,70vh)]">
718734
<CommandPaletteResults
719735
groups={displayedGroups}
736+
highlightedItemValue={highlightedItemValue}
720737
isActionsOnly={isActionsOnly}
721738
keybindings={keybindings}
722739
onExecuteItem={executeItem}
@@ -736,10 +753,12 @@ function OpenCommandPaletteDialog() {
736753
</Kbd>
737754
<span className={cn("text-muted-foreground/80")}>Navigate</span>
738755
</KbdGroup>
739-
<KbdGroup className="items-center gap-1.5">
740-
<Kbd>Enter</Kbd>
741-
<span className={cn("text-muted-foreground/80")}>Select</span>
742-
</KbdGroup>
756+
{!canSubmitBrowsePath || hasHighlightedBrowseItem ? (
757+
<KbdGroup className="items-center gap-1.5">
758+
<Kbd>Enter</Kbd>
759+
<span className={cn("text-muted-foreground/80")}>Select</span>
760+
</KbdGroup>
761+
) : null}
743762
{isSubmenu ? (
744763
<KbdGroup className="items-center gap-1.5">
745764
<Kbd>Backspace</Kbd>

0 commit comments

Comments
 (0)