Skip to content
TypeScript

feat(web): add composer and PR number shortcuts (#11615)

Bilal Bakr9130d932f4dd
diff --git a/apps/server/src/keybindings.ts b/apps/server/src/keybindings.ts
index 1795808bc17..08084a94df2 100644
--- a/apps/server/src/keybindings.ts
+++ b/apps/server/src/keybindings.ts
@@ -45,7 +45,7 @@ import { writeFileStringAtomically } from "./atomicWrite.ts";
import { fromJsonStringPretty, fromLenientJson } from "@t3tools/shared/schemaJson";
import {
DEFAULT_KEYBINDINGS,
- DEFAULT_RESOLVED_KEYBINDINGS,
+ mergeWithDefaultKeybindings,
compileResolvedKeybindingRule,
compileResolvedKeybindingsConfig,
parseKeybindingShortcut,
@@ -201,25 +201,6 @@ function invalidEntryIssue(index: number, detail: string): ServerConfigIssue {
};
}
-function mergeWithDefaultKeybindings(custom: ResolvedKeybindingsConfig): ResolvedKeybindingsConfig {
- if (custom.length === 0) {
- return [...DEFAULT_RESOLVED_KEYBINDINGS];
- }
-
- const overriddenCommands = new Set(custom.map((binding) => binding.command));
- const retainedDefaults = DEFAULT_RESOLVED_KEYBINDINGS.filter(
- (binding) => !overriddenCommands.has(binding.command),
- );
- const merged = [...retainedDefaults, ...custom];
-
- if (merged.length <= MAX_KEYBINDINGS_COUNT) {
- return merged;
- }
-
- // Keep the latest rules when the config exceeds max size; later rules have higher precedence.
- return merged.slice(-MAX_KEYBINDINGS_COUNT);
-}
-
/**
* Keybindings - Service tag for keybinding configuration operations.
*/
diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsx
index 3e3f834658e..7b7ffe626bc 100644
--- a/apps/web/src/components/BranchToolbar.tsx
+++ b/apps/web/src/components/BranchToolbar.tsx
@@ -8,7 +8,17 @@ import {
HistoryIcon,
ScaleIcon,
} from "lucide-react";
-import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
+import {
+ type Ref,
+ memo,
+ useImperativeHandle,
+ useCallback,
+ useEffect,
+ useLayoutEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
@@ -25,7 +35,10 @@ import {
resolvePreviousWorktreeSeed,
shouldShowEnvironmentIndicator,
} from "./BranchToolbar.logic";
-import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
+import {
+ BranchToolbarBranchSelector,
+ type BranchToolbarBranchSelectorHandle,
+} from "./BranchToolbarBranchSelector";
import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";
import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";
import { Button } from "./ui/button";
@@ -46,7 +59,13 @@ import { measureRestingComposerControls } from "./chat/restingComposerControlsMe
import { resolveRestingComposerControlsNaturalWidth } from "./composerFooterLayout";
import { cn } from "~/lib/utils";
+export interface BranchToolbarHandle {
+ openBranchPicker: () => void;
+ usePreviousWorktree: () => void;
+}
+
interface BranchToolbarProps {
+ ref?: Ref<BranchToolbarHandle>;
environmentId: EnvironmentId;
threadId: ThreadId;
showGitControls: boolean;
@@ -169,6 +188,10 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
render={<Button variant="ghost" size="xs" />}
className="min-w-0 max-w-[48%] flex-initial justify-start font-normal text-muted-foreground/70 text-xs! hover:text-foreground/80"
data-composer-context-control
+ data-composer-shortcut={[
+ showEnvironmentPicker && !envLocked ? "composer.host" : "",
+ !envModeLocked ? "composer.workspace" : "",
+ ].join(" ")}
>
{triggerContent}
<ChevronDownIcon className="size-3 shrink-0 opacity-50" />
@@ -438,6 +461,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
}
export const BranchToolbar = memo(function BranchToolbar({
+ ref,
environmentId,
threadId,
showGitControls,
@@ -458,6 +482,7 @@ export const BranchToolbar = memo(function BranchToolbar({
composerControlsHostRef,
contextStripVisible = true,
}: BranchToolbarProps) {
+ const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);
const threadRef = useMemo(
() => scopeThreadRef(environmentId, threadId),
[environmentId, threadId],
@@ -518,6 +543,25 @@ export const BranchToolbar = memo(function BranchToolbar({
});
}, [activeProjectRef, draftId, previousWorktreeSeed, setDraftThreadContext, threadRef]);
+ useImperativeHandle(
+ ref,
+ () => ({
+ openBranchPicker: () => branchSelectorRef.current?.open(),
+ usePreviousWorktree: () => {
+ if (!showGitControls || !canUsePreviousWorktree || !previousWorktreeSeed) return;
+ onUsePreviousWorktree();
+ onComposerFocusRequest?.();
+ },
+ }),
+ [
+ canUsePreviousWorktree,
+ onComposerFocusRequest,
+ onUsePreviousWorktree,
+ previousWorktreeSeed,
+ showGitControls,
+ ],
+ );
+
const showEnvironmentPicker = Boolean(
availableEnvironments && availableEnvironments.length > 1 && onEnvironmentChange,
);
@@ -618,6 +662,7 @@ export const BranchToolbar = memo(function BranchToolbar({
{showGitControls ? (
<BranchToolbarBranchSelector
+ ref={branchSelectorRef}
className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
environmentId={environmentId}
threadId={threadId}
diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx
index 4bb5f0aefd8..5f35c14de41 100644
--- a/apps/web/src/components/BranchToolbarBranchSelector.tsx
+++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx
@@ -15,6 +15,7 @@ import {
useDeferredValue,
useEffect,
useId,
+ useImperativeHandle,
useLayoutEffect,
useMemo,
useOptimistic,
@@ -22,6 +23,7 @@ import {
useState,
useTransition,
type MouseEvent as ReactMouseEvent,
+ type Ref,
} from "react";
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
@@ -72,7 +74,12 @@ import {
import { stackedThreadToast, toastManager } from "./ui/toast";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
+export interface BranchToolbarBranchSelectorHandle {
+ open: () => void;
+}
+
interface BranchToolbarBranchSelectorProps {
+ ref?: Ref<BranchToolbarBranchSelectorHandle>;
className?: string;
environmentId: EnvironmentId;
threadId: ThreadId;
@@ -92,6 +99,7 @@ function toBranchActionErrorMessage(error: unknown): string {
}
export function BranchToolbarBranchSelector({
+ ref,
className,
environmentId,
threadId,
@@ -535,6 +543,17 @@ export function BranchToolbarBranchSelector({
}
}, []);
+ useImperativeHandle(
+ ref,
+ () => ({
+ open: () => {
+ if (isInitialBranchesLoadPending || isBranchActionPending) return;
+ handleOpenChange(true);
+ },
+ }),
+ [handleOpenChange, isBranchActionPending, isInitialBranchesLoadPending],
+ );
+
const [showTopBranchScrollFade, setShowTopBranchScrollFade] = useState(false);
const [showBottomBranchScrollFade, setShowBottomBranchScrollFade] = useState(false);
const fetchNextBranchPage = useCallback(() => {
diff --git a/apps/web/src/components/BranchToolbarEnvModeSelector.tsx b/apps/web/src/components/BranchToolbarEnvModeSelector.tsx
index 4685dbf1ecd..a350931fbf4 100644
--- a/apps/web/src/components/BranchToolbarEnvModeSelector.tsx
+++ b/apps/web/src/components/BranchToolbarEnvModeSelector.tsx
@@ -93,6 +93,7 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
size="xs"
className="min-w-0 shrink font-normal text-xs!"
aria-label="Workspace"
+ data-composer-shortcut="composer.workspace"
data-composer-context-control
>
{effectiveEnvMode === "worktree" ? (
diff --git a/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx b/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx
index 861acee419e..0fa879c78a5 100644
--- a/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx
+++ b/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx
@@ -95,6 +95,7 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
size="xs"
className="min-w-0 max-w-full font-normal text-xs!"
aria-label="Run on"
+ data-composer-shortcut="composer.host"
data-composer-context-control
>
{autoEnvironmentLabel ? (
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index cc8e43f4673..0b6262387a9 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -219,7 +219,7 @@ import {
deriveAgentPanelModel,
foldSubagentActivities,
} from "@t3tools/client-runtime/state/subagentRuntime";
-import { BranchToolbar } from "./BranchToolbar";
+import { BranchToolbar, type BranchToolbarHandle } from "./BranchToolbar";
import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings";
import ThreadTerminalDrawer from "./ThreadTerminalDrawer";
import {
@@ -1617,6 +1617,7 @@ export default function ChatView(props: ChatViewProps) {
const composerTerminalContextsRef = useRef<TerminalContextDraft[]>([]);
const localComposerRef = useRef<ChatComposerHandle | null>(null);
const composerRef = useComposerHandleContext() ?? localComposerRef;
+ const branchToolbarRef = useRef<BranchToolbarHandle>(null);
const pasteAsTextShortcutUntilRef = useRef(0);
const [restingComposerControlsHost, setRestingComposerControlsHost] =
useState<HTMLDivElement | null>(null);
@@ -6397,6 +6398,17 @@ export default function ChatView(props: ChatViewProps) {
terminalUiOpenByThreadRef.current[activeThreadKey] = current;
}, [activeThreadKey, focusComposer, terminalUiState.terminalOpen]);
+ const getShortcutContext = useCallback(
+ () => ({
+ terminalFocus: getTerminalFocusOwner() !== null,
+ terminalOpen: Boolean(terminalUiState.terminalOpen),
+ previewFocus: isPreviewFocused(),
+ previewOpen: previewPanelOpen,
+ modelPickerOpen: composerRef.current?.isModelPickerOpen() ?? false,
+ }),
+ [composerRef, previewPanelOpen, terminalUiState.terminalOpen],
+ );
+
useEffect(() => {
const handler = (event: globalThis.KeyboardEvent) => {
if (preventRepeatedTerminalCloseShortcut(event, keybindings)) {
@@ -6417,13 +6429,7 @@ export default function ChatView(props: ChatViewProps) {
if (event.defaultPrevented && terminalFocusOwner === null) {
return;
}
- const shortcutContext = {
- terminalFocus: terminalFocusOwner !== null,
- terminalOpen: Boolean(terminalUiState.terminalOpen),
- previewFocus: isPreviewFocused(),
- previewOpen: previewPanelOpen,
- modelPickerOpen: composerRef.current?.isModelPickerOpen() ?? false,
- };
+ const shortcutContext = getShortcutContext();
if (
!shortcutContext.terminalFocus &&
@@ -6588,7 +6594,33 @@ export default function ChatView(props: ChatViewProps) {
if (command === "modelPicker.toggle") {
event.preventDefault();
event.stopPropagation();
- composerRef.current?.toggleModelPicker();
+ if (!event.repeat) composerRef.current?.toggleModelPicker();
+ return;
+ }
+
+ if (
+ command === "composer.host" ||
+ command === "composer.effort" ||
+ command === "composer.mode" ||
+ command === "composer.workspace"
+ ) {
+ event.preventDefault();
+ event.stopPropagation();
+ if (!event.repeat) composerRef.current?.openControl(command);
+ return;
+ }
+
+ if (command === "composer.branch") {
+ event.preventDefault();
+ event.stopPropagation();
+ if (!event.repeat) branchToolbarRef.current?.openBranchPicker();
+ return;
+ }
+
+ if (command === "composer.previousWorktree") {
+ event.preventDefault();
+ event.stopPropagation();
+ if (!event.repeat) branchToolbarRef.current?.usePreviousWorktree();
return;
}
@@ -6643,7 +6675,7 @@ export default function ChatView(props: ChatViewProps) {
supportsSettlement,
confirmAndUnpinThread,
copyActiveThreadReference,
- previewPanelOpen,
+ getShortcutContext,
toggleRightPanel,
toggleRightPanelMaximized,
toggleTerminalVisibility,
@@ -8708,6 +8740,10 @@ export default function ChatView(props: ChatViewProps) {
// reader's feet. A link the agent wrote can open any other one here, and that one has to be
// checkable out like it is anywhere else.
<PullRequestDetailPanel
+ getShortcutContext={getShortcutContext}
+ shortcutsEnabled={
+ rightPanelOpen && activeRightPanelSurface?.id === renderedRightPanelSurface.id
+ }
key={`${renderedRightPanelSurface.host ?? ""}:${renderedRightPanelSurface.repository}#${renderedRightPanelSurface.number}`}
environmentId={activeThread.environmentId}
onSelectPullRequest={(reference) => {
@@ -9231,6 +9267,7 @@ export default function ChatView(props: ChatViewProps) {
{mountComposerContextStrip && (
<div className="pointer-events-auto">
<BranchToolbar
+ ref={branchToolbarRef}
environmentId={activeThread.environmentId}
threadId={activeThread.id}
showGitControls={isGitRepo}
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index fafdee59e04..efaa9d6ece2 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -15,6 +15,7 @@ import {
} from "../../questionAttachments";
import type {
ApprovalRequestId,
+ KeybindingCommand,
AssistantCitation,
ChatFileAttachment,
EnvironmentId,
@@ -62,7 +63,7 @@ import {
useState,
useSyncExternalStore,
} from "react";
-import { createPortal } from "react-dom";
+import { createPortal, flushSync } from "react-dom";
import {
clampCollapsedComposerCursor,
type ComposerSubmissionIntent,
@@ -1103,6 +1104,7 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
<TooltipTrigger
render={
<ComposerSelectControl
+ data-composer-shortcut="composer.mode"
size={size}
className={size === "xs" ? undefined : "font-medium"}
aria-label="Runtime mode"
@@ -1231,6 +1233,7 @@ export interface ChatComposerHandle {
) => boolean;
openModelPicker: () => void;
toggleModelPicker: () => void;
+ openControl: (command: KeybindingCommand) => void;
isModelPickerOpen: () => boolean;
compactContext: () => void;
readSnapshot: () => {
@@ -5743,6 +5746,28 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
openModelPicker();
}
},
+ openControl: (command) => {
+ if (composerBlurFrameRef.current !== null) {
+ window.cancelAnimationFrame(composerBlurFrameRef.current);
+ composerBlurFrameRef.current = null;
+ }
+ flushSync(() => {
+ setIsComposerScrollCollapsed(false);
+ setIsComposerFocused(true);
+ });
+ const shell = composerFormRef.current?.closest('[data-slot="composer-shell"]');
+ const trigger = Array.from(
+ shell?.querySelectorAll<HTMLButtonElement>(
+ `button[data-composer-shortcut~="${command}"]:not(:disabled)`,
+ ) ?? [],
+ ).find(
+ (element) =>
+ !element.closest("[inert]") && element.checkVisibility({ visibilityProperty: true }),
+ );
+ if (!trigger) return;
+ trigger.focus({ preventScroll: true });
+ trigger.click();
+ },
compactContext: compactThreadContext,
isModelPickerOpen: () => isComposerModelPickerOpen,
readSnapshot: () => {
diff --git a/apps/web/src/components/chat/CompactComposerControlsMenu.tsx b/apps/web/src/components/chat/CompactComposerControlsMenu.tsx
index 039f12d4087..78cfb7b8d8f 100644
--- a/apps/web/src/components/chat/CompactComposerControlsMenu.tsx
+++ b/apps/web/src/components/chat/CompactComposerControlsMenu.tsx
@@ -40,6 +40,9 @@ export const CompactComposerControlsMenu = memo(function CompactComposerControls
variant="ghost"
className={size === "xs" ? "shrink-0" : "shrink-0 px-2"}
aria-label="More composer controls"
+ data-composer-shortcut={
+ props.traitsMenuContent ? "composer.mode composer.effort" : "composer.mode"
+ }
/>
}
>
diff --git a/apps/web/src/components/chat/ModelPickerContent.test.ts b/apps/web/src/components/chat/ModelPickerContent.test.ts
index 5b9cfd0ff5f..50db51bfa06 100644
--- a/apps/web/src/components/chat/ModelPickerContent.test.ts
+++ b/apps/web/src/components/chat/ModelPickerContent.test.ts
@@ -8,6 +8,7 @@ import { describe, expect, it } from "vite-plus/test";
import { deriveProviderInstanceEntries } from "../../providerInstances";
import {
+ adjacentModelPickerProvider,
resolveModelPickerSelectedModel,
shouldIncludeModelPickerOption,
shouldOfferModelPickerSetup,
@@ -213,3 +214,74 @@ describe("shouldOfferModelPickerSetup", () => {
).toBe(true);
});
});
+
+describe("adjacentModelPickerProvider", () => {
+ const codex = entry("ready", "codex");
+ const claude = entry("ready", "claudeAgent");
+ const unavailable = entry("error");
+ const input = {
+ entries: [codex, unavailable, claude],
+ disabledInstanceIds: undefined,
+ selectableUnavailableInstanceIds: undefined,
+ };
+
+ it("wraps through favorites and ready instances, skipping unavailable providers", () => {
+ expect(
+ adjacentModelPickerProvider({ ...input, selectedInstanceId: codex.instanceId, direction: 1 }),
+ ).toBe(claude.instanceId);
+ expect(
+ adjacentModelPickerProvider({ ...input, selectedInstanceId: "favorites", direction: -1 }),
+ ).toBe(claude.instanceId);
+ expect(
+ adjacentModelPickerProvider({
+ ...input,
+ selectedInstanceId: claude.instanceId,
+ direction: 1,
+ }),
+ ).toBe("favorites");
+ });
+
+ it("keeps thread locks and the selected unavailable catalog", () => {
+ expect(
+ adjacentModelPickerProvider({
+ ...input,
+ disabledInstanceIds: new Set([claude.instanceId]),
+ selectedInstanceId: codex.instanceId,
+ direction: 1,
+ }),
+ ).toBe("favorites");
+ expect(
+ adjacentModelPickerProvider({
+ ...input,
+ selectableUnavailableInstanceIds: new Set([unavailable.instanceId]),
+ selectedInstanceId: codex.instanceId,
+ direction: 1,
+ }),
+ ).toBe(unavailable.instanceId);
+ });
+
+ it("handles an empty catalog and a removed selection in either direction", () => {
+ expect(
+ adjacentModelPickerProvider({
+ ...input,
+ entries: [],
+ selectedInstanceId: codex.instanceId,
+ direction: -1,
+ }),
+ ).toBe("favorites");
+ expect(
+ adjacentModelPickerProvider({
+ ...input,
+ selectedInstanceId: unavailable.instanceId,
+ direction: 1,
+ }),
+ ).toBe("favorites");
+ expect(
+ adjacentModelPickerProvider({
+ ...input,
+ selectedInstanceId: unavailable.instanceId,
+ direction: -1,
+ }),
+ ).toBe(claude.instanceId);
+ });
+});
diff --git a/apps/web/src/components/chat/ModelPickerContent.tsx b/apps/web/src/components/chat/ModelPickerContent.tsx
index 63dea7844c4..5ee3743a33e 100644
--- a/apps/web/src/components/chat/ModelPickerContent.tsx
+++ b/apps/web/src/components/chat/ModelPickerContent.tsx
@@ -113,6 +113,34 @@ export function shouldOfferModelPickerSetup(
);
}
+export function adjacentModelPickerProvider(input: {
+ entries: ReadonlyArray<ProviderInstanceEntry>;
+ selectedInstanceId: ProviderInstanceId | "favorites";
+ direction: 1 | -1;
+ disabledInstanceIds: ReadonlySet<ProviderInstanceId> | undefined;
+ selectableUnavailableInstanceIds: ReadonlySet<ProviderInstanceId> | undefined;
+}) {
+ const providers: Array<ProviderInstanceId | "favorites"> = [
+ "favorites",
+ ...input.entries
+ .filter(
+ (entry) =>
+ !input.disabledInstanceIds?.has(entry.instanceId) &&
+ (isProviderInstancePickerReady(entry) ||
+ input.selectableUnavailableInstanceIds?.has(entry.instanceId)),
+ )
+ .map((entry) => entry.instanceId),
+ ];
+ const index = providers.indexOf(input.selectedInstanceId);
+ return providers[
+ index < 0
+ ? input.direction === 1
+ ? 0
+ : providers.length - 1
+ : (index + input.direction + providers.length) % providers.length
+ ]!;
+}
+
const EMPTY_MODEL_JUMP_LABELS = new Map<string, string>();
function ModelListSeparator() {
@@ -687,6 +715,20 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
platform: navigator.platform,
context: modelJumpShortcutContext,
});
+ if (command === "modelPicker.previousProvider" || command === "modelPicker.nextProvider") {
+ event.preventDefault();
+ event.stopPropagation();
+ const next = adjacentModelPickerProvider({
+ entries: sidebarInstanceEntries,
+ selectedInstanceId,
+ direction: command === "modelPicker.nextProvider" ? 1 : -1,
+ disabledInstanceIds: lockedDisabledInstanceIds,
+ selectableUnavailableInstanceIds,
+ });
+ setSearchQuery("");
+ handleSelectInstance(next);
+ return;
+ }
const jumpIndex = modelPickerJumpIndexFromCommand(command ?? "");
if (jumpIndex === null) {
return;
@@ -710,7 +752,17 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
return () => {
window.removeEventListener("keydown", onWindowKeyDown, true);
};
- }, [handleModelSelect, keybindings, modelJumpModelKeys, modelJumpShortcutContext]);
+ }, [
+ handleModelSelect,
+ handleSelectInstance,
+ keybindings,
+ lockedDisabledInstanceIds,
+ modelJumpModelKeys,
+ modelJumpShortcutContext,
+ selectableUnavailableInstanceIds,
+ selectedInstanceId,
+ sidebarInstanceEntries,
+ ]);
useLayoutEffect(() => {
setShowTopScrollFade(false);
@@ -737,6 +789,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
<ModelPickerSidebar
selectedInstanceId={selectedInstanceId}
onSelectInstance={handleSelectInstance}
+ onFocusSearch={focusSearchInput}
instanceEntries={sidebarInstanceEntries}
showFavorites
{...(selectableUnavailableInstanceIds ? { selectableUnavailableInstanceIds } : {})}
@@ -805,6 +858,28 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
onKeyDown={(e) => {
+ if (
+ showSidebar &&
+ !e.altKey &&
+ !e.ctrlKey &&
+ !e.metaKey &&
+ ((e.key === "ArrowLeft" && !e.shiftKey && searchQuery.length === 0) ||
+ (e.key === "Tab" && e.shiftKey))
+ ) {
+ const sidebar = e.currentTarget
+ .closest("[data-model-picker-content]")
+ ?.querySelector("[data-model-picker-sidebar]");
+ const button =
+ sidebar?.querySelector<HTMLButtonElement>(
+ 'button[aria-pressed="true"]:not(:disabled)',
+ ) ?? sidebar?.querySelector<HTMLButtonElement>("button:not(:disabled)");
+ if (button) {
+ e.preventDefault();
+ e.stopPropagation();
+ button.focus();
+ return;
+ }
+ }
if (e.key === "Escape") {
e.preventDefault();
e.stopPropagation();
diff --git a/apps/web/src/components/chat/ModelPickerSidebar.tsx b/apps/web/src/components/chat/ModelPickerSidebar.tsx
index dd53270268b..30f9e3ce809 100644
--- a/apps/web/src/components/chat/ModelPickerSidebar.tsx
+++ b/apps/web/src/components/chat/ModelPickerSidebar.tsx
@@ -1,3 +1,4 @@
+import { Toolbar } from "@base-ui/react/toolbar";
import { type ProviderInstanceId } from "@t3tools/contracts";
import { memo, useLayoutEffect, useRef, useState } from "react";
import { SparklesIcon, StarIcon } from "lucide-react";
@@ -43,6 +44,7 @@ const PICKER_TOOLTIP_CLASS = "max-w-64 text-balance font-normal leading-snug";
export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
selectedInstanceId: ProviderInstanceId | "favorites";
onSelectInstance: (instanceId: ProviderInstanceId | "favorites") => void;
+ onFocusSearch: () => void;
/**
* Instance entries to render as rail buttons. Each entry becomes one icon
* keyed by `instanceId`, so the default built-in Codex and a user-authored
@@ -87,7 +89,20 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
}, [props.instanceEntries, props.selectedInstanceId, showFavorites]);
return (
- <div className="w-11 shrink-0 overflow-hidden bg-muted/30" data-model-picker-sidebar="true">
+ <Toolbar.Root
+ className="w-11 shrink-0 overflow-hidden bg-muted/30"
+ data-model-picker-sidebar="true"
+ aria-label="Providers"
+ orientation="vertical"
+ onKeyDown={(event) => {
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
+ if (event.key === "ArrowRight") {
+ event.preventDefault();
+ props.onFocusSearch();
+ return;
+ }
+ }}
+ >
<div className="h-full overflow-y-auto overscroll-contain [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
<div ref={sidebarContentRef} className="relative flex min-h-full flex-col gap-1 p-1">
{selectedIndicatorTop !== null ? (
@@ -107,16 +122,17 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
<Tooltip>
<TooltipTrigger
render={
- <button
+ <Toolbar.Button
className={cn(
"relative isolate flex w-full cursor-pointer aspect-square items-center justify-center rounded-md transition-colors hover:bg-[color-mix(in_srgb,var(--popover)_90%,var(--contrast-foreground))] focus-visible:bg-[color-mix(in_srgb,var(--popover)_90%,var(--contrast-foreground))] focus-visible:outline-none",
)}
onClick={() => handleSelect("favorites")}
type="button"
aria-label="Favorites"
+ aria-pressed={props.selectedInstanceId === "favorites"}
>
<StarIcon className="size-5 fill-current shrink-0" aria-hidden />
- </button>
+ </Toolbar.Button>
}
/>
<TooltipPopup
@@ -155,7 +171,7 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
: entry.displayName;
const button = (
- <button
+ <Toolbar.Button
className={cn(
"relative isolate flex w-full cursor-pointer aspect-square items-center justify-center rounded-md transition-colors hover:bg-[color-mix(in_srgb,var(--popover)_90%,var(--contrast-foreground))] focus-visible:bg-[color-mix(in_srgb,var(--popover)_90%,var(--contrast-foreground))] focus-visible:outline-none",
isDisabled && "opacity-50 cursor-not-allowed hover:bg-transparent",
@@ -171,6 +187,8 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
setHoveredInstanceId((current) => (current === entry.instanceId ? null : current))
}
disabled={isDisabled}
+ focusableWhenDisabled={!isDisabled}
+ aria-pressed={isSelected}
type="button"
aria-label={
isUnavailable || isContextDisabled
@@ -203,7 +221,7 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
<SparklesIcon className="size-2" />
</span>
) : null}
- </button>
+ </Toolbar.Button>
);
const trigger = isDisabled ? (
@@ -234,6 +252,6 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
})}
</div>
</div>
- </div>
+ </Toolbar.Root>
);
});
diff --git a/apps/web/src/components/chat/TraitsPicker.tsx b/apps/web/src/components/chat/TraitsPicker.tsx
index 47ce59efde5..0a863e0bd44 100644
--- a/apps/web/src/components/chat/TraitsPicker.tsx
+++ b/apps/web/src/components/chat/TraitsPicker.tsx
@@ -618,6 +618,7 @@ export const TraitsPicker = memo(function TraitsPicker({
<MenuTrigger
render={
<ComposerControl
+ data-composer-shortcut={isComposerOwned ? "composer.effort" : undefined}
variant={triggerVariant ?? "ghost"}
size={size}
className={cn(
diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
index dbd2eb255c4..cbbfaf1f33f 100644
--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
@@ -1,4 +1,5 @@
import { parseChangeRequestUrl } from "@t3tools/shared/changeRequestUrl";
+import { useAtomValue } from "@effect/atom-react";
import { usePullRequestStack } from "~/state/usePullRequestStack";
import { RefreshIcon } from "~/components/ui/refresh-icon";
import { scopedThreadKey, scopeProjectRef } from "@t3tools/client-runtime/environment";
@@ -21,6 +22,7 @@ import {
ArrowUpRightIcon,
BookOpenIcon,
CircleDotIcon,
+ CopyIcon,
ChevronDownIcon,
ExternalLinkIcon,
FileDiffIcon,
@@ -49,6 +51,7 @@ import {
type MouseEvent as ReactMouseEvent,
useCallback,
useEffect,
+ useEffectEvent,
useLayoutEffect,
useMemo,
useRef,
@@ -57,7 +60,14 @@ import {
import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
import { useNewThreadHandler } from "~/hooks/useHandleNewThread";
-import { useCopyToClipboard, writeTextToClipboard } from "~/hooks/useCopyToClipboard";
+import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
+import { isCommandPaletteOpen } from "~/commandPaletteBus";
+import {
+ resolveShortcutCommand,
+ shortcutLabelForCommand,
+ type ShortcutMatchContext,
+} from "~/keybindings";
+import { primaryServerKeybindingsAtom } from "~/state/server";
import { useClientSettings } from "~/hooks/useSettings";
import {
deriveLogicalProjectKeyFromSettings,
@@ -104,6 +114,7 @@ import {
MenuRadioGroup,
MenuRadioItem,
MenuSeparator,
+ MenuShortcut,
MenuTrigger,
} from "../ui/menu";
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
@@ -457,6 +468,8 @@ function PullRequestBaseFreshnessWarning({
export function PullRequestDetailPanel({
environmentId,
+ shortcutsEnabled,
+ getShortcutContext,
threadRef = null,
reference: requestedReference,
listEntry = null,
@@ -469,6 +482,8 @@ export function PullRequestDetailPanel({
onSelectPullRequest,
}: {
environmentId: EnvironmentId;
+ shortcutsEnabled: boolean;
+ getShortcutContext: () => ShortcutMatchContext;
onSelectPullRequest?: ((reference: PullRequestRef) => void) | undefined;
/**
* The thread this panel sits beside, if any. Links that are not the pull
@@ -707,6 +722,32 @@ export function PullRequestDetailPanel({
},
[activity, coreDetail],
);
+ const keybindings = useAtomValue(primaryServerKeybindingsAtom);
+ const { copyToClipboard: copyReference } = useCopyToClipboard<string>({
+ target: "pull request reference",
+ onCopy: (label) => toastManager.add({ type: "success", title: `${label} copied` }),
+ onError: (error, label) =>
+ toastManager.add({
+ type: "error",
+ title: `Failed to copy ${label}`,
+ description: error.message,
+ }),
+ });
+ const copyFromShortcut = useEffectEvent((event: KeyboardEvent) => {
+ if (!shortcutsEnabled || event.defaultPrevented || isCommandPaletteOpen()) return;
+ const command = resolveShortcutCommand(event, keybindings, {
+ context: getShortcutContext(),
+ });
+ if (command !== "pullRequest.copyNumber") return;
+ event.preventDefault();
+ event.stopPropagation();
+ if (!event.repeat) copyReference(`#${reference.number}`, "PR number");
+ });
+ useEffect(() => {
+ const onKeyDown = (event: KeyboardEvent) => copyFromShortcut(event);
+ window.addEventListener("keydown", onKeyDown, true);
+ return () => window.removeEventListener("keydown", onKeyDown, true);
+ }, []);
useEffect(() => {
if (detail?.autoMergeMethod !== undefined) setMergeMethod(detail.autoMergeMethod);
}, [detail?.autoMergeMethod, pullRequestKey]);
@@ -2080,9 +2121,19 @@ export function PullRequestDetailPanel({
<ArrowUpRightIcon className="size-3.5" />
{openOnHostLabel(detail.provider)}
</MenuItem>
- <MenuItem onClick={() => void writeTextToClipboard(detail.url)}>
+ <MenuItem onClick={() => copyReference(detail.url, "PR link")}>
<LinkIcon className="size-3.5" />
Copy link
+ <MenuShortcut>
+ {shortcutLabelForCommand(keybindings, "thread.copyReference")}
+ </MenuShortcut>
+ </MenuItem>
+ <MenuItem onClick={() => copyReference(`#${reference.number}`, "PR number")}>
+ <CopyIcon className="size-3.5" />
+ Copy PR number
+ <MenuShortcut>
+ {shortcutLabelForCommand(keybindings, "pullRequest.copyNumber")}
+ </MenuShortcut>
</MenuItem>
{detail.state === "open" && can("close") ? (
<>
diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
index 41e3cc2ec30..d55b047e663 100644
--- a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
+++ b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
@@ -17,6 +17,32 @@ import {
} from "./KeybindingsSettings.logic";
describe("KeybindingsSettings.logic", () => {
+ it("lists composer, provider, and pull request commands with editable defaults", () => {
+ const rows = buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, "");
+ for (const command of [
+ "composer.host",
+ "composer.effort",
+ "composer.mode",
+ "composer.workspace",
+ "composer.branch",
+ "composer.previousWorktree",
+ "modelPicker.previousProvider",
+ "modelPicker.nextProvider",
+ "thread.copyReference",
+ "pullRequest.copyNumber",
+ ]) {
+ expect(rows.find((row) => row.command === command)).toMatchObject({
+ source: "Default",
+ conflicts: [],
+ });
+ }
+ });
+ it("finds the existing URL shortcut in Settings", () => {
+ const rows = buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, "PR URL");
+ expect(rows).toEqual([
+ expect.objectContaining({ command: "thread.copyReference", key: "mod+shift+c" }),
+ ]);
+ });
it("builds searchable rows with readable key and when values", () => {
const rows = buildKeybindingRows(
[
diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.ts
index 65589d1bcd9..7119d9ee4e5 100644
--- a/apps/web/src/components/settings/KeybindingsSettings.logic.ts
+++ b/apps/web/src/components/settings/KeybindingsSettings.logic.ts
@@ -209,6 +209,7 @@ export function buildKeybindingRows(
return rowsWithConflicts.filter((row) => {
return (
row.command.toLowerCase().includes(normalizedQuery) ||
+ commandLabel(row.command).toLowerCase().includes(normalizedQuery) ||
row.key.toLowerCase().includes(normalizedQuery) ||
row.when.toLowerCase().includes(normalizedQuery) ||
row.source.toLowerCase().includes(normalizedQuery)
@@ -275,6 +276,7 @@ export function buildKeybindingCommandOptions(
}
export function commandLabel(command: KeybindingCommand): string {
+ if (command === "thread.copyReference") return "Thread: Copy PR URL or Thread ID";
const raw = String(command);
if (raw.startsWith("script.") && raw.endsWith(".run")) {
return `Run Script: ${titleCaseCommandSegment(raw.slice("script.".length, -".run".length))}`;
diff --git a/apps/web/src/components/settings/KeybindingsSettings.tsx b/apps/web/src/components/settings/KeybindingsSettings.tsx
index 85e32b1bf85..d02f15939c5 100644
--- a/apps/web/src/components/settings/KeybindingsSettings.tsx
+++ b/apps/web/src/components/settings/KeybindingsSettings.tsx
@@ -26,7 +26,7 @@ import {
type ServerRemoveKeybindingInput,
type ServerUpsertKeybindingInput,
} from "@t3tools/contracts";
-import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
+import { mergeWithDefaultKeybindings } from "@t3tools/shared/keybindings";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
@@ -1334,7 +1334,11 @@ export function KeybindingsSettingsPanel() {
// fan out to every connected environment in the selection, so one
// shortcut change reaches each machine the user runs T3 Code on.
const { environment: primaryEnvironment, connectedEnvironments } = useSettingsScope();
- const keybindings = primaryEnvironment?.serverConfig?.keybindings ?? DEFAULT_RESOLVED_KEYBINDINGS;
+ const serverKeybindings = primaryEnvironment?.serverConfig?.keybindings;
+ const keybindings = useMemo(
+ () => mergeWithDefaultKeybindings(serverKeybindings ?? []),
+ [serverKeybindings],
+ );
const keybindingsConfigPath = primaryEnvironment?.serverConfig?.keybindingsConfigPath ?? null;
const availableEditors = primaryEnvironment?.serverConfig?.availableEditors ?? [];
const upsertKeybinding = useAtomCommand(serverEnvironment.upsertKeybinding, {
diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts
index 598e08e5977..1e9e8adc7ba 100644
--- a/apps/web/src/keybindings.test.ts
+++ b/apps/web/src/keybindings.test.ts
@@ -1,4 +1,9 @@
import { assert, describe, it } from "vite-plus/test";
+import {
+ compileResolvedKeybindingsConfig,
+ DEFAULT_RESOLVED_KEYBINDINGS,
+ mergeWithDefaultKeybindings,
+} from "@t3tools/shared/keybindings";
import {
type KeybindingCommand,
@@ -1057,3 +1062,194 @@ describe("plus key parsing", () => {
);
});
});
+
+describe("composer and pull request shortcuts", () => {
+ it("fills missing number shortcuts without replacing the saved URL binding", () => {
+ const olderServerBindings = DEFAULT_RESOLVED_KEYBINDINGS.filter(
+ (binding) =>
+ binding.command !== "pullRequest.copyNumber" && binding.command !== "thread.copyReference",
+ );
+ const bindings = mergeWithDefaultKeybindings([
+ ...olderServerBindings,
+ ...compileResolvedKeybindingsConfig([
+ { key: "mod+shift+8", command: "thread.copyReference", when: "!terminalFocus" },
+ ]),
+ ]);
+ for (const [key, command] of [
+ ["k", "pullRequest.copyNumber"],
+ ["8", "thread.copyReference"],
+ ["c", null],
+ ["y", null],
+ ] as const) {
+ assert.strictEqual(
+ resolveShortcutCommand(event({ key, metaKey: true, shiftKey: true }), bindings, {
+ platform: "MacIntel",
+ }),
+ command,
+ );
+ }
+ });
+
+ it.each(["terminalOpen", "previewFocus", "previewOpen", "modelPickerOpen"])(
+ "honors custom PR shortcut conditions for %s",
+ (condition) => {
+ const bindings = compileResolvedKeybindingsConfig([
+ { key: "mod+shift+k", command: "thread.copyReference", when: condition },
+ { key: "mod+shift+k", command: "pullRequest.copyNumber", when: `!${condition}` },
+ ]);
+ const input = event({ key: "k", ctrlKey: true, shiftKey: true });
+ for (const enabled of [false, true]) {
+ assert.strictEqual(
+ resolveShortcutCommand(input, bindings, {
+ platform: "Linux",
+ context: { [condition]: enabled },
+ }),
+ enabled ? "thread.copyReference" : "pullRequest.copyNumber",
+ );
+ }
+ },
+ );
+
+ const shortcuts = [
+ ["h", "composer.host"],
+ ["e", "composer.effort"],
+ ["a", "composer.mode"],
+ ["x", "composer.workspace"],
+ ["g", "composer.branch"],
+ ["l", "composer.previousWorktree"],
+ ["c", "thread.copyReference"],
+ ["k", "pullRequest.copyNumber"],
+ ] as const;
+
+ for (const platform of ["MacIntel", "Win32", "Linux"]) {
+ it.each(shortcuts)(
+ `resolves %s on ${platform} and leaves terminal input alone`,
+ (key, command) => {
+ const input = event({
+ key,
+ shiftKey: true,
+ metaKey: platform === "MacIntel",
+ ctrlKey: platform !== "MacIntel",
+ });
+ assert.strictEqual(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform,
+ context: { terminalFocus: false },
+ }),
+ command,
+ );
+ assert.isNull(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform,
+ context: { terminalFocus: true },
+ }),
+ );
+ },
+ );
+ }
+
+ for (const platform of ["MacIntel", "Win32", "Linux"]) {
+ it.each([
+ ["s", "thread.settle"],
+ ["p", "thread.pin"],
+ ])(`preserves the existing %s shortcut on ${platform}`, (key, command) => {
+ assert.strictEqual(
+ resolveShortcutCommand(
+ event({
+ key,
+ shiftKey: true,
+ metaKey: platform === "MacIntel",
+ ctrlKey: platform !== "MacIntel",
+ }),
+ DEFAULT_RESOLVED_KEYBINDINGS,
+ { platform },
+ ),
+ command,
+ );
+ });
+ }
+
+ const altEffortBindings = compileResolvedKeybindingsConfig([
+ { key: "mod+alt+e", command: "composer.effort", when: "!terminalFocus" },
+ ]);
+
+ it("leaves AltGr text entry alone with a custom Alt binding", () => {
+ for (const platform of ["Win32", "Linux"]) {
+ const input = event({
+ key: "€",
+ code: "KeyE",
+ ctrlKey: true,
+ altKey: true,
+ getModifierState: (key) => key === "AltGraph",
+ });
+ assert.isNull(resolveShortcutCommand(input, altEffortBindings, { platform }));
+ assert.strictEqual(
+ resolveShortcutCommand({ ...input, getModifierState: () => false }, altEffortBindings, {
+ platform,
+ }),
+ "composer.effort",
+ );
+ }
+ });
+
+ it("keeps Firefox modifier reporting usable on Windows and macOS", () => {
+ const getModifierState = (key: string) => key === "AltGraph";
+ assert.strictEqual(
+ resolveShortcutCommand(
+ event({ key: "e", ctrlKey: true, altKey: true, getModifierState }),
+ altEffortBindings,
+ { platform: "Win32" },
+ ),
+ "composer.effort",
+ );
+ assert.strictEqual(
+ resolveShortcutCommand(
+ event({ key: "´", code: "KeyE", metaKey: true, altKey: true, getModifierState }),
+ altEffortBindings,
+ { platform: "MacIntel" },
+ ),
+ "composer.effort",
+ );
+ });
+
+ it.each(shortcuts)("uses a custom binding for %s", (_key, command) => {
+ const bindings = compileResolvedKeybindingsConfig([
+ { key: "mod+shift+y", command, when: "!terminalFocus" },
+ ]);
+ assert.strictEqual(
+ resolveShortcutCommand(
+ event({ key: "Y", code: "KeyY", ctrlKey: true, shiftKey: true }),
+ bindings,
+ { platform: "Linux" },
+ ),
+ command,
+ );
+ });
+
+ for (const platform of ["MacIntel", "Win32", "Linux"]) {
+ it.each([
+ ["ArrowUp", "modelPicker.previousProvider"],
+ ["ArrowDown", "modelPicker.nextProvider"],
+ ] as const)(`limits %s to the model picker on ${platform}`, (key, command) => {
+ const input = event({
+ key,
+ shiftKey: true,
+ metaKey: platform === "MacIntel",
+ ctrlKey: platform !== "MacIntel",
+ });
+ assert.strictEqual(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform,
+ context: { modelPickerOpen: true },
+ }),
+ command,
+ );
+ assert.isNull(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform,
+ context: { modelPickerOpen: false },
+ }),
+ );
+ });
+ }
+});
diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts
index b9a5b728289..8683ad3c68a 100644
--- a/apps/web/src/keybindings.ts
+++ b/apps/web/src/keybindings.ts
@@ -11,6 +11,7 @@ import {
import { isMacPlatform } from "./lib/utils";
export interface ShortcutEventLike {
+ getModifierState?: (key: "AltGraph") => boolean;
type?: string;
code?: string;
key: string;
@@ -123,6 +124,12 @@ function matchesShortcut(
shortcut: KeybindingShortcut,
platform = navigator.platform,
): boolean {
+ if (
+ !isMacPlatform(platform) &&
+ event.getModifierState?.("AltGraph") &&
+ !/^[a-z0-9]$/i.test(event.key)
+ )
+ return false;
if (!matchesShortcutModifiers(event, shortcut, platform)) return false;
return resolveEventKeys(event).has(shortcut.key);
}
diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsx
index 973c406f690..642740f3032 100644
--- a/apps/web/src/routes/_chat.pull-requests.tsx
+++ b/apps/web/src/routes/_chat.pull-requests.tsx
@@ -151,6 +151,16 @@ import { cn } from "~/lib/utils";
import { primaryServerKeybindingsAtom } from "~/state/server";
import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
+function getShortcutContext() {
+ return {
+ terminalFocus: isTerminalFocused(),
+ terminalOpen: false,
+ previewFocus: false,
+ previewOpen: false,
+ modelPickerOpen: false,
+ };
+}
+
export interface PullRequestsSearch extends PullRequestListPreferences {
/**
* Narrows the list to one server. Absent means every connected one, which is the default the
@@ -1925,7 +1935,7 @@ function PullRequestsRouteView() {
const onKeyDown = (event: KeyboardEvent) => {
if (event.defaultPrevented || isCommandPaletteOpen()) return;
const command = resolveShortcutCommand(event, keybindings, {
- context: { terminalFocus: isTerminalFocused() },
+ context: getShortcutContext(),
});
if (command === "rightPanel.close") closeActiveSurfaceFromShortcut(event);
if (command === "rightPanel.toggle") toggleRightPanelFromShortcut(event);
@@ -1992,6 +2002,8 @@ function PullRequestsRouteView() {
pullRequestStatusSeeds={listedPullRequestTabStatuses}
>
<PullRequestDetailPanel
+ getShortcutContext={getShortcutContext}
+ shortcutsEnabled={activePullRequestSurface?.id === renderedPullRequestSurface.id}
key={renderedPullRequestSurface.id}
environmentId={panelEnvironmentId}
onSelectPullRequest={(reference) => {
diff --git a/apps/web/src/state/server.ts b/apps/web/src/state/server.ts
index 11fd2e7dc0f..f4161dfb454 100644
--- a/apps/web/src/state/server.ts
+++ b/apps/web/src/state/server.ts
@@ -10,7 +10,7 @@ import {
} from "@t3tools/contracts";
import { createServerEnvironmentAtoms } from "@t3tools/client-runtime/state/server";
import { createEnvironmentServerConfigsAtom } from "@t3tools/client-runtime/state/shell";
-import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
+import { mergeWithDefaultKeybindings } from "@t3tools/shared/keybindings";
import * as Option from "effect/Option";
import { AsyncResult, Atom } from "effect/unstable/reactivity";
@@ -90,9 +90,8 @@ export const primaryServerProvidersAtom = Atom.make(
get(primaryServerConfigAtom)?.providers ?? EMPTY_SERVER_PROVIDERS,
).pipe(Atom.withLabel("web-primary-server-providers"));
-export const primaryServerKeybindingsAtom = Atom.make(
- (get): ServerConfig["keybindings"] =>
- get(primaryServerConfigAtom)?.keybindings ?? DEFAULT_RESOLVED_KEYBINDINGS,
+export const primaryServerKeybindingsAtom = Atom.make((get): ServerConfig["keybindings"] =>
+ mergeWithDefaultKeybindings(get(primaryServerConfigAtom)?.keybindings ?? []),
).pipe(Atom.withLabel("web-primary-server-keybindings"));
export const primaryServerAvailableEditorsAtom = Atom.make(
diff --git a/docs/user/keybindings.md b/docs/user/keybindings.md
index 4e46e97a3a5..55652591053 100644
--- a/docs/user/keybindings.md
+++ b/docs/user/keybindings.md
@@ -3,6 +3,31 @@
Customize shortcuts in **Settings → Keybindings** on web and desktop. That page
also lists the command IDs and defaults available in your version.
+## Composer controls
+
+Use `mod+shift+m` to choose a model and `mod+shift+h` to choose a host.
+Use `mod+shift+e` for effort, `mod+shift+a` for access mode, `mod+shift+x` for the
+workspace, and `mod+shift+g` for the Git branch. The workspace menu includes the
+current checkout, a new worktree, and the previous worktree when available.
+Use `mod+shift+l` to reuse the previous worktree directly.
+
+In the model picker, press Left in an empty search field or Shift+Tab to reach
+the provider list. Use Up/Down to move and Enter to choose. Right returns to
+model search. `mod+shift+up` and `mod+shift+down` switch providers directly and clear the
+search. These provider shortcuts can also be changed in Settings.
+
+These shortcuts run inside the focused web or desktop client. `mod` uses Command
+on macOS and Ctrl on Windows and Linux, including GNOME, KDE Plasma, Niri, and
+Hyprland. If a custom desktop shortcut takes the same keys, choose another binding
+in Settings.
+
+## Copy pull request references
+
+With a PR open in the right panel or on the Pull Requests page, use `mod+shift+c`
+to copy its URL and `mod+shift+k` to copy its number with a `#` prefix.
+Both shortcuts can be changed in Settings. Search for “Copy PR URL or Thread ID”
+or “Copy Number”. They copy the selected PR and leave terminal input alone.
+
## Edit the configuration file
Keybindings live on the environment's machine, in
diff --git a/packages/contracts/src/keybindings.test.ts b/packages/contracts/src/keybindings.test.ts
index 27e096cbb2e..14579c74119 100644
--- a/packages/contracts/src/keybindings.test.ts
+++ b/packages/contracts/src/keybindings.test.ts
@@ -122,6 +122,13 @@ it.effect("parses keybinding rules", () =>
});
assert.strictEqual(parsedThreadCopyReference.command, "thread.copyReference");
+ const parsedPullRequestCopyNumber = yield* decode(KeybindingRule, {
+ key: "mod+shift+k",
+ command: "pullRequest.copyNumber",
+ when: "!terminalFocus",
+ });
+ assert.strictEqual(parsedPullRequestCopyNumber.command, "pullRequest.copyNumber");
+
const parsedThreadStop = yield* decode(KeybindingRule, {
key: "mod+escape",
command: "thread.stop",
diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts
index 2be8aa91f7a..a285d2fcf4a 100644
--- a/packages/contracts/src/keybindings.ts
+++ b/packages/contracts/src/keybindings.ts
@@ -47,6 +47,8 @@ export type ThreadKeybindingCommand = (typeof THREAD_KEYBINDING_COMMANDS)[number
const MODEL_PICKER_KEYBINDING_COMMANDS = [
"modelPicker.toggle",
+ "modelPicker.previousProvider",
+ "modelPicker.nextProvider",
...MODEL_PICKER_JUMP_KEYBINDING_COMMANDS,
] as const;
export type ModelPickerKeybindingCommand = (typeof MODEL_PICKER_KEYBINDING_COMMANDS)[number];
@@ -61,6 +63,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"rightPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.close",
+ "pullRequest.copyNumber",
"diff.toggle",
"preview.toggle",
"preview.refresh",
@@ -73,6 +76,12 @@ export const STATIC_KEYBINDING_COMMANDS = [
"projectSearch.toggle",
"themeEditor.toggle",
"composer.stash",
+ "composer.host",
+ "composer.effort",
+ "composer.mode",
+ "composer.workspace",
+ "composer.previousWorktree",
+ "composer.branch",
"chat.new",
"chat.newLocal",
"editor.openFavorite",
diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.ts
index 1107873c828..8d73c07f34a 100644
--- a/packages/shared/src/keybindings.ts
+++ b/packages/shared/src/keybindings.ts
@@ -44,6 +44,15 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ key: "mod+shift+o", command: "chat.new", when: "!terminalFocus" },
{ key: "mod+shift+n", command: "chat.newLocal", when: "!terminalFocus" },
{ key: "mod+shift+m", command: "modelPicker.toggle", when: "!terminalFocus" },
+ { key: "mod+shift+h", command: "composer.host", when: "!terminalFocus" },
+ { key: "mod+shift+e", command: "composer.effort", when: "!terminalFocus" },
+ { key: "mod+shift+a", command: "composer.mode", when: "!terminalFocus" },
+ { key: "mod+shift+x", command: "composer.workspace", when: "!terminalFocus" },
+ { key: "mod+shift+g", command: "composer.branch", when: "!terminalFocus" },
+ { key: "mod+shift+l", command: "composer.previousWorktree", when: "!terminalFocus" },
+ { key: "mod+shift+k", command: "pullRequest.copyNumber", when: "!terminalFocus" },
+ { key: "mod+shift+arrowup", command: "modelPicker.previousProvider", when: "modelPickerOpen" },
+ { key: "mod+shift+arrowdown", command: "modelPicker.nextProvider", when: "modelPickerOpen" },
{ key: "mod+o", command: "editor.openFavorite" },
{ key: "mod+shift+[", command: "thread.previous" },
{ key: "mod+shift+]", command: "thread.next" },
@@ -299,3 +308,23 @@ export function compileResolvedKeybindingsConfig(
}
export const DEFAULT_RESOLVED_KEYBINDINGS = compileResolvedKeybindingsConfig(DEFAULT_KEYBINDINGS);
+
+export function mergeWithDefaultKeybindings(
+ custom: ResolvedKeybindingsConfig,
+): ResolvedKeybindingsConfig {
+ if (custom.length === 0) {
+ return [...DEFAULT_RESOLVED_KEYBINDINGS];
+ }
+
+ const overriddenCommands = new Set(custom.map((binding) => binding.command));
+ const retainedDefaults = DEFAULT_RESOLVED_KEYBINDINGS.filter(
+ (binding) => !overriddenCommands.has(binding.command),
+ );
+ const merged = [...retainedDefaults, ...custom];
+
+ if (merged.length <= MAX_KEYBINDINGS_COUNT) {
+ return merged;
+ }
+
+ return merged.slice(-MAX_KEYBINDINGS_COUNT);
+}