Switch projects from New Workspace with ⌘P/Ctrl+P (#2110)
* feat(app): add ⌘P shortcut to switch project on New Workspace screen Opens the existing project picker with its search focused so the project can be switched from the keyboard (type + Enter) instead of clicking the badge and then the project. Wires a new "workspace.project.pick" action through the standard keyboard pipeline (binding -> route passthrough -> dispatcher), handled by a screen-scoped handler on the New Workspace screen that is only registered while the screen is mounted and there are projects to pick. Because preventDefault only fires when a handler handles the key, ⌘P/Ctrl+P still triggers native print everywhere else. Adds a Settings -> Shortcuts help row (rebindable) and the "Switch project" label across all locales. * test(app): cover project picker shortcut --------- Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
co-authored by
Mohamed Boudra
parent
b55acfc60f
commit
f8dd0fc2e0
@@ -55,6 +55,8 @@ import {
|
||||
type PendingWorkspaceDraftSetup,
|
||||
} from "@/stores/workspace-draft-submission-store";
|
||||
import { useKeyboardShiftStyle } from "@/hooks/use-keyboard-shift-style";
|
||||
import { useKeyboardActionHandler } from "@/hooks/use-keyboard-action-handler";
|
||||
import type { KeyboardActionId } from "@/keyboard/keyboard-action-dispatcher";
|
||||
import { useFormPreferences } from "@/hooks/use-form-preferences";
|
||||
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
|
||||
import { getForgePresentation } from "@/git/forge";
|
||||
@@ -181,6 +183,8 @@ interface PickerOptionData {
|
||||
const BRANCH_OPTION_PREFIX = "branch:";
|
||||
const PR_OPTION_PREFIX = "github-pr:";
|
||||
const PROJECT_ICON_FALLBACK_FONT_SIZE = 10;
|
||||
// Stable reference so the keyboard-action handler doesn't re-register each render.
|
||||
const PROJECT_PICK_ACTIONS: readonly KeyboardActionId[] = ["workspace.project.pick"];
|
||||
// Height of a single picker-trigger badge. The Base-row spacer reserves exactly
|
||||
// this so toggling Isolation to Local hides the row without shifting the form.
|
||||
const BADGE_HEIGHT = 28;
|
||||
@@ -1788,6 +1792,22 @@ 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.
|
||||
const handleProjectPick = useCallback(() => {
|
||||
openProjectPicker();
|
||||
return true;
|
||||
}, [openProjectPicker]);
|
||||
useKeyboardActionHandler({
|
||||
handlerId: "new-workspace-project-pick",
|
||||
actions: PROJECT_PICK_ACTIONS,
|
||||
enabled: projectPickerOptions.length > 0,
|
||||
priority: 0,
|
||||
handle: handleProjectPick,
|
||||
});
|
||||
|
||||
const openIsolationPicker = useCallback(() => {
|
||||
setIsolationPickerOpen(true);
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user