Open the project chooser with Cmd+N on New workspace (#9741)

* feat(app): open the project chooser with the new workspace shortcut

* fix(app): claim project shortcuts while projects load

* fix(app): keep project shortcuts owned by the focused screen
This commit is contained in:
Mohamed Boudra
2026-11-15 14:30:58 +07:00
committed by GitHub
parent dc2dfdab93
commit da3be528e9
5 changed files with 48 additions and 13 deletions
@@ -160,6 +160,22 @@ test.describe("New workspace entry points", () => {
}
});
test("Ctrl+N opens the project picker with search focused", async ({ page }) => {
const seeded: SeededWorkspace = await seedWorkspace({ repoPrefix: "entry-shortcut-" });
try {
await gotoAppShell(page);
await waitForSidebarHydration(page);
await openGlobalNewWorkspaceComposer(page);
await openGlobalNewWorkspaceComposer(page);
await page.goBack();
await openNewWorkspaceProjectPickerWithShortcut(page, "Control+N");
} finally {
await seeded.cleanup();
}
});
test("keeps the in-progress form when the remembered workspace is archived elsewhere", async ({
page,
}) => {
@@ -232,8 +232,11 @@ export async function expectNewWorkspaceControlsEnabled(page: Page): Promise<voi
});
}
export async function openNewWorkspaceProjectPickerWithShortcut(page: Page): Promise<void> {
await page.keyboard.press("Control+P");
export async function openNewWorkspaceProjectPickerWithShortcut(
page: Page,
shortcut = "Control+P",
): Promise<void> {
await page.keyboard.press(shortcut);
const searchInput = page.getByPlaceholder("Search projects");
await expect(searchInput).toBeVisible({ timeout: 30_000 });
@@ -3,7 +3,7 @@ import type { CreateWorkspaceRequestOptions } from "@getpaseo/client/internal/da
import type { AgentSnapshotPayload, CreationSnapshot } from "@getpaseo/protocol/messages";
import { encodeImages } from "@/utils/encode-images";
import { getHostRuntimeStore } from "@/runtime/host-runtime";
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import type { ReactNode } from "react";
import { useIsFocused } from "expo-router/react-navigation";
import { useTranslation } from "react-i18next";
@@ -188,7 +188,10 @@ function noopChangeAttachments() {}
function noopClearDraft() {}
// Stable reference so the keyboard-action handler doesn't re-register each render.
const PROJECT_PICK_ACTIONS: readonly KeyboardActionId[] = ["workspace.project.pick"];
const PROJECT_PICK_ACTIONS: readonly KeyboardActionId[] = [
"workspace.project.pick",
"workspace.new",
];
interface WorkspaceIsolationState {
isolation: "local" | "worktree";
@@ -907,6 +910,7 @@ export function NewWorkspaceScreen({
const isDraftHandoffActive = useIsNewWorkspaceDraftHandoffActive({ draftId, selectedServerId });
const isStillOnCreateScreen = useNewWorkspaceScreenPresence();
const isScreenFocused = useIsFocused();
const projectPickHandlerId = useId();
// Launch target: what the composer submits to (chat agent, or a terminal
// profile). Mirrors useWorkspaceIsolation's pattern below: the derived
@@ -1181,19 +1185,18 @@ export function NewWorkspaceScreen({
setProjectPickerOpen(true);
}, []);
// Cmd/Ctrl+P opens the project picker with its search focused so the user can
// switch projects from the keyboard. Registered only while this screen is
// mounted, so the shortcut doesn't swallow the browser's native print
// elsewhere; gated on having projects to pick.
// On this screen, both project-pick and new-workspace open the chooser.
// Take precedence over global new-workspace navigation to preserve the draft.
const handleProjectPick = useCallback(() => {
openProjectPicker();
return true;
}, [openProjectPicker]);
useKeyboardActionHandler({
handlerId: "new-workspace-project-pick",
handlerId: `new-workspace-project-pick:${projectPickHandlerId}`,
actions: PROJECT_PICK_ACTIONS,
enabled: projectPickerOptions.length > 0,
priority: 0,
enabled: isScreenFocused,
isActive: isStillOnCreateScreen,
priority: 10,
handle: handleProjectPick,
});
@@ -5,6 +5,8 @@ import { ChevronDown } from "lucide-react-native";
import { ComboboxTrigger } from "@/components/ui/combobox-trigger";
import { CONTROL_HEIGHTS } from "@/components/ui/control-geometry";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { Shortcut } from "@/components/ui/shortcut";
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
import { ICON_SIZE, type Theme } from "@/styles/theme";
/**
@@ -97,15 +99,17 @@ export interface FieldTriggerProps extends FieldTriggerContentProps {
disabled?: boolean;
/** Desktop hover hint; badges only, since a field shows its label. */
tooltip?: string;
shortcutAction?: string;
testID?: string;
}
/** A field trigger that anchors a Combobox. */
export const FieldTrigger = forwardRef<View, FieldTriggerProps>(function FieldTrigger(
{ accessibilityLabel, onPress, disabled = false, tooltip, testID, ...content },
{ accessibilityLabel, onPress, disabled = false, tooltip, shortcutAction, testID, ...content },
ref,
): ReactElement {
const style = useFieldTriggerStyle(content.variant, disabled);
const shortcutKeys = useShortcutKeys(shortcutAction ?? null);
const trigger = (
<ComboboxTrigger
ref={ref}
@@ -128,7 +132,10 @@ export const FieldTrigger = forwardRef<View, FieldTriggerProps>(function FieldTr
{trigger}
</TooltipTrigger>
<TooltipContent side="top" align="center" offset={8}>
<Text style={styles.tooltipText}>{tooltip}</Text>
<View style={styles.tooltipRow}>
<Text style={styles.tooltipText}>{tooltip}</Text>
{shortcutKeys ? <Shortcut chord={shortcutKeys} /> : null}
</View>
</TooltipContent>
</Tooltip>
);
@@ -210,6 +217,11 @@ const styles = StyleSheet.create((theme) => ({
detail: {
color: theme.colors.foregroundExtraMuted,
},
tooltipRow: {
flexDirection: "row",
alignItems: "center",
gap: theme.spacing[2],
},
tooltipText: {
fontSize: theme.fontSize.base,
color: theme.colors.popoverForeground,
@@ -209,6 +209,7 @@ export function useNewWorkspaceForm(props: NewWorkspaceFormProps): ReactElement
label={t("newWorkspace.fields.project")}
accessibilityLabel="Workspace project"
tooltip={t("newWorkspace.tooltips.project")}
shortcutAction="new-workspace"
icon={projectIcon}
value={project.triggerLabel}
onPress={project.open}