diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx index b52b357f84..ef6b64be9c 100644 --- a/apps/web/src/components/AppSidebarLayout.tsx +++ b/apps/web/src/components/AppSidebarLayout.tsx @@ -164,12 +164,9 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { { + it("assigns positional jump shortcuts to the first nine displayed items", () => { + const items = Array.from({ length: 10 }, (_, index) => ({ + kind: "action" as const, + value: `project-${index + 1}`, + searchTerms: [], + title: `Project ${index + 1}`, + icon: null, + shortcutCommand: "chat.new" as const, + run: async () => undefined, + })); + + expect(enumerateCommandPaletteItems(items).map((item) => item.shortcutCommand)).toEqual([ + "thread.jump.1", + "thread.jump.2", + "thread.jump.3", + "thread.jump.4", + "thread.jump.5", + "thread.jump.6", + "thread.jump.7", + "thread.jump.8", + "thread.jump.9", + undefined, + ]); + }); +}); + const LOCAL_ENVIRONMENT_ID = EnvironmentId.make("environment-local"); const PROJECT_ID = ProjectId.make("project-1"); diff --git a/apps/web/src/components/CommandPalette.logic.ts b/apps/web/src/components/CommandPalette.logic.ts index ab53adbefb..a217d53b5b 100644 --- a/apps/web/src/components/CommandPalette.logic.ts +++ b/apps/web/src/components/CommandPalette.logic.ts @@ -1,4 +1,8 @@ -import { type KeybindingCommand, type FilesystemBrowseEntry } from "@t3tools/contracts"; +import { + type KeybindingCommand, + type FilesystemBrowseEntry, + THREAD_JUMP_KEYBINDING_COMMANDS, +} from "@t3tools/contracts"; import type { SidebarThreadSortOrder } from "@t3tools/contracts/settings"; import * as Arr from "effect/Array"; import * as Result from "effect/Result"; @@ -52,6 +56,18 @@ export interface CommandPaletteView { readonly initialQuery?: string; } +export function enumerateCommandPaletteItems( + items: ReadonlyArray, +): CommandPaletteActionItem[] { + return items.map((item, index) => { + const shortcutCommand = THREAD_JUMP_KEYBINDING_COMMANDS[index]; + if (shortcutCommand) return { ...item, shortcutCommand }; + + const { shortcutCommand: _shortcutCommand, ...itemWithoutShortcut } = item; + return itemWithoutShortcut; + }); +} + export type CommandPaletteMode = "root" | "root-browse" | "submenu" | "submenu-browse"; export function filterBrowseEntries(input: { diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx index b0c37bda55..bb83dfa569 100644 --- a/apps/web/src/components/CommandPalette.tsx +++ b/apps/web/src/components/CommandPalette.tsx @@ -95,6 +95,7 @@ import { buildProjectActionItems, buildRootGroups, buildThreadActionItems, + enumerateCommandPaletteItems, type CommandPaletteActionItem, type CommandPaletteSubmenuItem, type CommandPaletteView, @@ -112,7 +113,7 @@ import { ProjectFavicon } from "./ProjectFavicon"; import { ThreadRowLeadingStatus, ThreadRowTrailingStatus } from "./ThreadStatusIndicators"; import { primaryServerKeybindingsAtom, primaryServerProvidersAtom } from "../state/server"; import { resolveDefaultProviderModelSelection } from "../providerInstances"; -import { resolveShortcutCommand } from "../keybindings"; +import { resolveShortcutCommand, threadJumpIndexFromCommand } from "../keybindings"; import { Command, CommandDialog, @@ -686,29 +687,30 @@ function OpenCommandPaletteDialog(props: { const projectThreadItems = useMemo( () => - buildProjectActionItems({ - projects, - valuePrefix: "new-thread-in", - shortcutCommand: "chat.new", - icon: (project) => ( - - ), - runProject: async (project) => { - await startNewThreadInProjectFromContext( - { - activeDraftThread, - activeThread: activeThread ?? undefined, - defaultProjectRef, - handleNewThread, - }, - scopeProjectRef(project.environmentId, project.id), - ); - }, - }), + enumerateCommandPaletteItems( + buildProjectActionItems({ + projects, + valuePrefix: "new-thread-in", + icon: (project) => ( + + ), + runProject: async (project) => { + await startNewThreadInProjectFromContext( + { + activeDraftThread, + activeThread: activeThread ?? undefined, + defaultProjectRef, + handleNewThread, + }, + scopeProjectRef(project.environmentId, project.id), + ); + }, + }), + ), [activeDraftThread, activeThread, defaultProjectRef, handleNewThread, projects], ); @@ -997,7 +999,13 @@ function OpenCommandPaletteDialog(props: { : projectThreadItems; pushPaletteView({ addonIcon: , - groups: [{ value: "projects", label: "Projects", items: prioritized }], + groups: [ + { + value: "projects", + label: "Projects", + items: enumerateCommandPaletteItems(prioritized), + }, + ], }); }, [ clearOpenIntent, @@ -1545,6 +1553,22 @@ function OpenCommandPaletteDialog(props: { } function handleKeyDown(event: KeyboardEvent): void { + const command = resolveShortcutCommand(event, keybindings, { + platform: navigator.platform, + context: { modelPickerOpen: false }, + }); + if (threadJumpIndexFromCommand(command ?? "") !== null) { + const matchingItem = displayedGroups + .flatMap((group) => group.items) + .find((item) => item.shortcutCommand === command); + if (matchingItem) { + event.preventDefault(); + event.stopPropagation(); + executeItem(matchingItem); + return; + } + } + if (addProjectCloneFlow?.step === "repository" && event.key === "Enter") { event.preventDefault(); void submitAddProjectCloneFlow(); @@ -1896,37 +1920,35 @@ function OpenCommandPaletteDialog(props: { - Navigate + Navigate {addProjectCloneFlow?.step === "repository" ? ( Enter - - {remoteProjectButtonLabel ?? "Continue"} - + {remoteProjectButtonLabel ?? "Continue"} ) : !canSubmitBrowsePath || hasHighlightedBrowseItem ? ( Enter - Select + Select ) : null} {isSubmenu ? ( Backspace - Back + Back ) : null} Esc - Close + Close {canOpenProjectFromFileManager ? (