@devries-cameron20 / t3code-1 / commits / 3b8e7bbbe0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(web): add shortcuts to the surface dropdown (#7318)

Gianmarco committed Aug 19, 2026 at 06:31 UTC 3b8e7bbbe0c49b00630f0c89e931056df679a650
2 files changed +149 -58
apps/web/src/components/RightPanelTabs.test.tsx
+42 -1
@@ -2,7 +2,22 @@ import type { DesktopPreviewFavicon, PreviewSessionSnapshot } from "@t3tools/con
2 import { renderToStaticMarkup } from "react-dom/server";
3 import { describe, expect, it } from "vite-plus/test";
4
5 -import { RightPanelTabs, tabMuteMenuItem } from "./RightPanelTabs";
5 +import { RightPanelTabs, surfaceShortcutActionForKey, tabMuteMenuItem } from "./RightPanelTabs";
6 +
7 +function shortcutEvent(
8 + key: string,
9 + overrides: Partial<Parameters<typeof surfaceShortcutActionForKey>[1]> = {},
10 +): Parameters<typeof surfaceShortcutActionForKey>[1] {
11 + return {
12 + key,
13 + altKey: false,
14 + ctrlKey: false,
15 + defaultPrevented: false,
16 + isComposing: false,
17 + metaKey: false,
18 + ...overrides,
19 + };
20 +}
21
22 const previewSurface = {
23 id: "browser:tab-1" as const,
@@ -125,6 +140,32 @@ describe("RightPanelTabs preview favicon", () => {
140 });
141 });
142
143 +describe("surface shortcuts", () => {
144 + const actions = [
145 + { shortcut: "B", available: true, label: "Browser" },
146 + { shortcut: "D", available: false, label: "Diff" },
147 + ] as const;
148 +
149 + it("matches available surface shortcuts case-insensitively", () => {
150 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("b"))).toBe(actions[0]);
151 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("B"))).toBe(actions[0]);
152 + });
153 +
154 + it("does not activate unavailable surfaces", () => {
155 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("d"))).toBeNull();
156 + });
157 +
158 + it("leaves modified, composing, and already-handled key events alone", () => {
159 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("b", { metaKey: true }))).toBeNull();
160 + expect(
161 + surfaceShortcutActionForKey(actions, shortcutEvent("b", { isComposing: true })),
162 + ).toBeNull();
163 + expect(
164 + surfaceShortcutActionForKey(actions, shortcutEvent("b", { defaultPrevented: true })),
165 + ).toBeNull();
166 + });
167 +});
168 +
169 describe("RightPanelTabs audio indicator", () => {
170 // A muted tab only shows the indicator while it is actually making sound:
171 // arming mute on a quiet tab is deliberate and stays invisible until there
apps/web/src/components/RightPanelTabs.tsx
+107 -57
@@ -31,7 +31,7 @@ import { readLocalApi } from "~/localApi";
31 import { Button } from "~/components/ui/button";
32 import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
33 import { Kbd } from "~/components/ui/kbd";
34 -import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
34 +import { Menu, MenuItem, MenuPopup, MenuShortcut, MenuTrigger } from "~/components/ui/menu";
35 import { ScrollArea } from "~/components/ui/scroll-area";
36 import { faviconUrlForOrigin } from "~/lib/favicon";
37 import { useTheme } from "~/hooks/useTheme";
@@ -173,6 +173,23 @@ function tabAudioState(overlay: DesktopPreviewOverlay | null): TabAudioState {
173 return overlay.audioMuted ? "muted" : "audible";
174 }
175
176 +type SurfaceShortcutEvent = Pick<
177 + KeyboardEvent,
178 + "altKey" | "ctrlKey" | "defaultPrevented" | "isComposing" | "key" | "metaKey"
179 +>;
180 +
181 +export function surfaceShortcutActionForKey<
182 + const Action extends { available: boolean; shortcut: string },
183 +>(actions: readonly Action[], event: SurfaceShortcutEvent): Action | null {
184 + if (event.defaultPrevented || event.isComposing) return null;
185 + if (event.metaKey || event.ctrlKey || event.altKey) return null;
186 + return (
187 + actions.find(
188 + (action) => action.available && action.shortcut.toLowerCase() === event.key.toLowerCase(),
189 + ) ?? null
190 + );
191 +}
192 +
193 function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
194 return (
195 <Tooltip>
@@ -185,6 +202,7 @@ function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement })
202 function SurfaceMenuItem(props: {
203 available: boolean;
204 disabledReason?: string;
205 + shortcut: string;
206 onClick: () => void;
207 children: ReactNode;
208 }) {
@@ -193,8 +211,10 @@ function SurfaceMenuItem(props: {
211 className={!props.available ? "data-disabled:pointer-events-auto" : undefined}
212 onClick={props.onClick}
213 disabled={!props.available}
214 + aria-keyshortcuts={props.shortcut}
215 >
216 {props.children}
217 + <MenuShortcut>{props.shortcut}</MenuShortcut>
218 </MenuItem>
219 );
220 if (props.available || !props.disabledReason) return item;
@@ -305,8 +325,8 @@ function RightPanelEmptyState(props: {
325 });
326 useEffect(() => {
327 const handler = (event: KeyboardEvent) => {
308 - if (event.defaultPrevented || event.isComposing) return;
309 - if (event.metaKey || event.ctrlKey || event.altKey) return;
328 + const action = surfaceShortcutActionForKey(shortcutActionsRef.current, event);
329 + if (!action) return;
330 if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
331 const target = event.target;
332 if (target instanceof HTMLElement) {
@@ -316,10 +336,6 @@ function RightPanelEmptyState(props: {
336 const editable = target.isContentEditable ? target : target.closest("[contenteditable]");
337 if (editable && (editable.textContent ?? "").trim().length > 0) return;
338 }
319 - const action = shortcutActionsRef.current.find(
320 - (candidate) => candidate.shortcut.toLowerCase() === event.key.toLowerCase(),
321 - );
322 - if (!action) return;
339 event.preventDefault();
340 event.stopPropagation();
341 action.onClick();
@@ -573,6 +589,67 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
589 const ownsDesktopTitleBar = isElectron && props.mode === "inline";
590 const { resolvedTheme } = useTheme();
591 const tabListRef = useRef<HTMLDivElement>(null);
592 + const [addSurfaceMenuOpen, setAddSurfaceMenuOpen] = useState(false);
593 +
594 + const addSurfaceActions = [
595 + {
596 + label: "Browser",
597 + icon: Globe2,
598 + shortcut: "B",
599 + available: props.browserAvailable,
600 + disabledReason: SURFACE_DISABLED_REASONS.browser,
601 + onClick: props.onAddBrowser,
602 + },
603 + {
604 + label: "Terminal",
605 + icon: TerminalSquare,
606 + shortcut: "T",
607 + available: props.terminalAvailable,
608 + disabledReason: SURFACE_DISABLED_REASONS.terminal,
609 + onClick: props.onAddTerminal,
610 + },
611 + {
612 + label: "Files",
613 + icon: Files,
614 + shortcut: "F",
615 + available: props.filesAvailable,
616 + disabledReason: SURFACE_DISABLED_REASONS.files,
617 + onClick: props.onAddFiles,
618 + },
619 + {
620 + label: "Diff",
621 + icon: FileDiff,
622 + shortcut: "D",
623 + available: props.diffAvailable,
624 + disabledReason: SURFACE_DISABLED_REASONS.diff,
625 + onClick: props.onAddDiff,
626 + },
627 + {
628 + label: "Pull request",
629 + icon: GitPullRequest,
630 + shortcut: "P",
631 + available: props.pullRequestAvailable,
632 + disabledReason: SURFACE_DISABLED_REASONS.pullRequest,
633 + onClick: props.onAddPullRequest,
634 + },
635 + {
636 + label: "Agents",
637 + icon: Bot,
638 + shortcut: "A",
639 + available: props.agentsAvailable,
640 + disabledReason: SURFACE_DISABLED_REASONS.agents,
641 + onClick: props.onAddAgents,
642 + },
643 + ] as const;
644 +
645 + const handleAddSurfaceMenuKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
646 + const action = surfaceShortcutActionForKey(addSurfaceActions, event.nativeEvent);
647 + if (!action) return;
648 + event.preventDefault();
649 + event.stopPropagation();
650 + setAddSurfaceMenuOpen(false);
651 + action.onClick();
652 + };
653
654 const handleTabContextMenu = useCallback(
655 async (event: ReactMouseEvent, surface: RightPanelSurface) => {
@@ -804,7 +881,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
881 );
882 })}
883 {props.surfaces.length > 0 ? (
807 - <Menu>
884 + <Menu open={addSurfaceMenuOpen} onOpenChange={setAddSurfaceMenuOpen}>
885 <MenuTrigger
886 render={
887 <Button
@@ -817,55 +894,28 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
894 >
895 <Plus className="size-3.5" />
896 </MenuTrigger>
820 - <MenuPopup align="start" side="bottom" sideOffset={6} className="min-w-44">
821 - <SurfaceMenuItem
822 - available={props.browserAvailable}
823 - disabledReason={SURFACE_DISABLED_REASONS.browser}
824 - onClick={props.onAddBrowser}
825 - >
826 - <Globe2 />
827 - Browser
828 - </SurfaceMenuItem>
829 - <SurfaceMenuItem
830 - available={props.terminalAvailable}
831 - disabledReason={SURFACE_DISABLED_REASONS.terminal}
832 - onClick={props.onAddTerminal}
833 - >
834 - <TerminalSquare />
835 - Terminal
836 - </SurfaceMenuItem>
837 - <SurfaceMenuItem
838 - available={props.filesAvailable}
839 - disabledReason={SURFACE_DISABLED_REASONS.files}
840 - onClick={props.onAddFiles}
841 - >
842 - <Files />
843 - Files
844 - </SurfaceMenuItem>
845 - <SurfaceMenuItem
846 - available={props.diffAvailable}
847 - disabledReason={SURFACE_DISABLED_REASONS.diff}
848 - onClick={props.onAddDiff}
849 - >
850 - <FileDiff />
851 - Diff
852 - </SurfaceMenuItem>
853 - <SurfaceMenuItem
854 - available={props.pullRequestAvailable}
855 - disabledReason={SURFACE_DISABLED_REASONS.pullRequest}
856 - onClick={props.onAddPullRequest}
857 - >
858 - <GitPullRequest />
859 - Pull request
860 - </SurfaceMenuItem>
861 - <SurfaceMenuItem
862 - available={props.agentsAvailable}
863 - disabledReason={SURFACE_DISABLED_REASONS.agents}
864 - onClick={props.onAddAgents}
865 - >
866 - <Bot />
867 - Agents
868 - </SurfaceMenuItem>
897 + <MenuPopup
898 + align="start"
899 + side="bottom"
900 + sideOffset={6}
901 + className="min-w-44"
902 + onKeyDownCapture={handleAddSurfaceMenuKeyDown}
903 + >
904 + {addSurfaceActions.map((action) => {
905 + const Icon = action.icon;
906 + return (
907 + <SurfaceMenuItem
908 + key={action.label}
909 + available={action.available}
910 + disabledReason={action.disabledReason}
911 + shortcut={action.shortcut}
912 + onClick={action.onClick}
913 + >
914 + <Icon />
915 + {action.label}
916 + </SurfaceMenuItem>
917 + );
918 + })}
919 </MenuPopup>
920 </Menu>
921 ) : null}