feat(web): open right panel tab menu with Mod+T (#15686)

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Bilal BakrandJulius Marminge authored and GitHub committed 2026-10-07 00:04:00 +00:00
1 parent ab28039ef7
commit 7202ba6660
7 files changed
+272 -1

No files matched your search

+5
View File
@@ -11603,6 +11603,8 @@ export default function ChatView(props: ChatViewProps) {
<RightPanelTabs
mode="inline"
open={rightPanelOpen}
keybindings={keybindings}
getShortcutContext={getShortcutContext}
maximized={rightPanelMaximized}
inlineSize={previewPanelInlineSize}
surfaces={renderedRightPanelSurfaces}
@@ -11650,6 +11652,9 @@ export default function ChatView(props: ChatViewProps) {
>
<RightPanelTabs
mode="sheet"
open={rightPanelOpen}
keybindings={keybindings}
getShortcutContext={getShortcutContext}
inlineSize={previewPanelInlineSize}
// Same effective inset as the closed-state titlebar controls
// (pr-3 in the tab bar plus this pixel equals the absolute
@@ -0,0 +1,221 @@
// @vitest-environment jsdom
import { act, type ComponentProps } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import {
compileResolvedKeybindingsConfig,
DEFAULT_RESOLVED_KEYBINDINGS,
} from "@t3tools/shared/keybindings";
import { RightPanelTabs } from "./RightPanelTabs";
vi.mock("~/hooks/useTheme", () => ({ useTheme: () => ({ resolvedTheme: "light" }) }));
vi.mock("~/browser/browserDefaults", () => ({ useBrowserDefaults: () => ({ profiles: [] }) }));
let root: Root;
let container: HTMLDivElement;
const addFiles = vi.fn();
const noop = () => undefined;
beforeEach(() => {
vi.useFakeTimers();
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
vi.stubGlobal(
"ResizeObserver",
class {
observe() {}
disconnect() {}
unobserve() {}
},
);
Object.defineProperty(Element.prototype, "getAnimations", {
configurable: true,
value: () => [],
});
vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
addFiles.mockClear();
container = document.createElement("div");
document.body.append(container);
root = createRoot(container);
});
afterEach(async () => {
await act(() => root.unmount());
container.remove();
vi.restoreAllMocks();
vi.unstubAllGlobals();
vi.useRealTimers();
});
async function renderPanel(overrides: Partial<ComponentProps<typeof RightPanelTabs>> = {}) {
await act(() =>
root.render(
<RightPanelTabs
mode="inline"
open
keybindings={DEFAULT_RESOLVED_KEYBINDINGS}
getShortcutContext={() => ({
terminalFocus: false,
terminalOpen: false,
previewFocus: false,
previewOpen: false,
isWeb: true,
isDesktop: false,
})}
surfaces={[]}
environmentId={null}
activeSurfaceId={null}
pendingSurfaceIds={new Set()}
previewSessions={{}}
desktopByTabId={{}}
terminalLabelsById={new Map()}
onActivate={noop}
onCloseSurface={noop}
onCloseOtherSurfaces={noop}
onCloseSurfacesToRight={noop}
onCloseAllSurfaces={noop}
onCopyFilePath={noop}
onAddBrowser={noop}
onAddBrowserInProfile={noop}
onAddTerminal={noop}
onAddDiff={noop}
onAddFiles={addFiles}
onAddPullRequest={noop}
onAddPullRequests={noop}
onAddDevice={noop}
browserAvailable={false}
terminalAvailable={false}
diffAvailable={false}
filesAvailable
pullRequestAvailable={false}
pullRequestsAvailable={false}
deviceAvailable={false}
{...overrides}
>
content
</RightPanelTabs>,
),
);
await act(() => vi.advanceTimersByTimeAsync(0));
await act(() => vi.advanceTimersToNextFrame());
}
async function press(key: string, options: KeyboardEventInit = {}) {
const event = new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true, ...options });
await act(() => (document.activeElement ?? document.body).dispatchEvent(event));
await act(() => vi.advanceTimersByTimeAsync(0));
await act(() => vi.advanceTimersToNextFrame());
return event;
}
describe("right panel new-tab shortcut", () => {
it.each(["MacIntel", "Win32", "Linux x86_64"])(
"opens the menu on %s and chooses a tab",
async (platform) => {
vi.spyOn(navigator, "platform", "get").mockReturnValue(platform);
await renderPanel();
const event = await press(
"t",
platform === "MacIntel" ? { metaKey: true } : { ctrlKey: true },
);
expect(event.defaultPrevented).toBe(true);
expect(document.querySelector('[role="menu"]')?.textContent).toContain(
"Linked pull requests",
);
expect(document.activeElement?.closest('[role="menu"]')).not.toBeNull();
expect(
(
await press("t", {
metaKey: platform === "MacIntel",
ctrlKey: platform !== "MacIntel",
repeat: true,
})
).defaultPrevented,
).toBe(true);
await press("f");
expect(addFiles).toHaveBeenCalledOnce();
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
},
);
it("leaves the shortcut alone while the mounted panel is closed", async () => {
await renderPanel({ open: false });
expect((await press("t", { metaKey: true })).defaultPrevented).toBe(false);
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
});
it.each(["Win32", "Linux x86_64"])(
"leaves Ctrl+T for the focused terminal on %s",
async (platform) => {
vi.spyOn(navigator, "platform", "get").mockReturnValue(platform);
await renderPanel({
getShortcutContext: () => ({
terminalFocus: true,
terminalOpen: true,
previewFocus: false,
previewOpen: false,
isWeb: true,
isDesktop: false,
}),
});
const terminal = document.createElement("textarea");
const onKeyDown = vi.fn();
terminal.addEventListener("keydown", onKeyDown);
container.append(terminal);
await act(() => terminal.focus());
const event = await press("t", { ctrlKey: true });
expect(event.defaultPrevented).toBe(false);
expect(onKeyDown).toHaveBeenCalledWith(event);
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
},
);
it("uses a custom binding from a text field and closes on Escape", async () => {
const input = document.createElement("input");
await renderPanel({
keybindings: compileResolvedKeybindingsConfig([{ key: "mod+y", command: "rightPanel.new" }]),
});
document.body.append(input);
input.focus();
expect((await press("t", { metaKey: true })).defaultPrevented).toBe(false);
await press("y", { metaKey: true });
expect(document.querySelector('[role="menu"]')).not.toBeNull();
await press("Escape");
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
expect(document.activeElement).toBe(
container.querySelector('[aria-label="Add panel surface"]'),
);
input.remove();
});
it("does not open over another popup or during text composition", async () => {
await renderPanel();
expect((await press("t", { metaKey: true, isComposing: true })).defaultPrevented).toBe(false);
const dialog = document.createElement("div");
dialog.dataset.slot = "dialog-popup";
container.append(dialog);
expect((await press("t", { metaKey: true })).defaultPrevented).toBe(false);
expect(document.querySelector('[role="menu"]')).toBeNull();
});
it("supports arrow keys with an existing tab in sheet mode and clears the menu on close", async () => {
const panel = {
mode: "sheet" as const,
surfaces: [{ id: "files" as const, kind: "files" as const }],
};
await renderPanel(panel);
await press("t", { metaKey: true });
await press("ArrowDown");
await press("ArrowDown");
await press("ArrowDown");
expect(document.activeElement?.textContent).toContain("Files");
await press("Enter");
expect(addFiles).toHaveBeenCalledOnce();
await press("t", { metaKey: true });
await renderPanel({ ...panel, open: false });
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
await renderPanel(panel);
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
});
});
@@ -1,6 +1,7 @@
import { EnvironmentId, type ThreadPullRequestLink } from "@t3tools/contracts";
import type { DesktopPreviewFavicon, PreviewSessionSnapshot } from "@t3tools/contracts";
import { renderToStaticMarkup } from "react-dom/server";
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
import { describe, expect, it } from "vite-plus/test";
import {
@@ -98,6 +99,15 @@ function renderTabs(
return renderToStaticMarkup(
<RightPanelTabs
mode="inline"
keybindings={DEFAULT_RESOLVED_KEYBINDINGS}
getShortcutContext={() => ({
terminalFocus: false,
terminalOpen: false,
previewFocus: false,
previewOpen: false,
isWeb: true,
isDesktop: false,
})}
surfaces={second ? [previewSurface, secondSurface] : [previewSurface]}
environmentId={null}
activeSurfaceId={previewSurface.id}
+32 -1
View File
@@ -11,6 +11,7 @@ import type {
PreviewSessionSnapshot,
ProjectId,
PullRequestState,
ResolvedKeybindingsConfig,
} from "@t3tools/contracts";
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
import {
@@ -32,6 +33,7 @@ import {
type ReactNode,
useCallback,
useEffect,
useEffectEvent,
useMemo,
useRef,
useState,
@@ -41,6 +43,7 @@ import { isElectron } from "~/env";
import type { DesktopPreviewOverlay } from "~/previewStateStore";
import type { RightPanelSurface } from "~/rightPanelStore";
import { cn } from "~/lib/utils";
import { resolveShortcutCommand, type ShortcutMatchContext } from "~/keybindings";
import { readLocalApi } from "~/localApi";
import { Button } from "~/components/ui/button";
import { MorphIcon } from "~/components/MorphIcon";
@@ -83,6 +86,8 @@ interface RightPanelTabsProps {
mode: PreviewPanelMode;
maximized?: boolean;
open?: boolean;
keybindings: ResolvedKeybindingsConfig;
getShortcutContext: () => ShortcutMatchContext;
/** Forwarded to PreviewPanelShell so this surface persists its own width. */
widthStorageKey?: string;
/** Forwarded to PreviewPanelShell as the initial width before a user resize. */
@@ -793,6 +798,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
const browserProfiles = useBrowserDefaults().profiles;
const { resolvedTheme } = useTheme();
const tabListRef = useRef<HTMLDivElement>(null);
const addSurfaceTriggerRef = useRef<HTMLButtonElement>(null);
const [renamingDevice, setRenamingDevice] = useState<string | null>(null);
const [addSurfaceMenuOpen, setAddSurfaceMenuOpen] = useState(false);
const [tabScrollState, setTabScrollState] = useState({
@@ -801,6 +807,30 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
canScrollRight: false,
});
if (props.open === false && addSurfaceMenuOpen) setAddSurfaceMenuOpen(false);
const onNewSurfaceKeyDown = useEffectEvent((event: KeyboardEvent) => {
if (event.defaultPrevented || event.isComposing) return;
if (
resolveShortcutCommand(event, props.keybindings, {
context: { ...props.getShortcutContext(), rightPanelOpen: true },
}) !== "rightPanel.new"
)
return;
if (!addSurfaceMenuOpen && document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
event.preventDefault();
event.stopPropagation();
if (!event.repeat) {
addSurfaceTriggerRef.current?.focus();
setAddSurfaceMenuOpen(true);
}
});
useEffect(() => {
if (props.open === false) return;
document.addEventListener("keydown", onNewSurfaceKeyDown, true);
return () => document.removeEventListener("keydown", onNewSurfaceKeyDown, true);
}, [props.open]);
const updateTabScrollState = useCallback(() => {
const viewport = tabScrollViewport(tabListRef.current);
if (!viewport) return;
@@ -1214,9 +1244,10 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
</div>
);
})}
{props.surfaces.length > 0 ? (
{props.open !== false ? (
<Menu open={addSurfaceMenuOpen} onOpenChange={setAddSurfaceMenuOpen}>
<MenuTrigger
ref={addSurfaceTriggerRef}
render={
<Button
aria-label="Add panel surface"
@@ -2215,6 +2215,8 @@ function PullRequestsRouteView() {
<RightPanelTabs
mode="inline"
open={rightPanelState.isOpen}
keybindings={keybindings}
getShortcutContext={getShortcutContext}
widthStorageKey="t3code:pull-request-panel-width"
// Default to roughly half the viewport: the PR list needs more
// room than a chat, so the 540px chat-preview default squashes
+1
View File
@@ -66,6 +66,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"terminal.new",
"terminal.close",
"rightPanel.toggle",
"rightPanel.new",
"threadPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.close",
+1
View File
@@ -126,6 +126,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ key: "mod+]", command: "navigation.forward", when: "!terminalFocus" },
{ key: "mod+j", command: "terminal.toggle" },
{ key: "mod+alt+b", command: "rightPanel.toggle" },
{ key: "mod+t", command: "rightPanel.new", when: "rightPanelOpen && !terminalFocus" },
{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },
{ key: "mod+shift+d", command: "terminal.splitVertical", when: "terminalFocus" },
{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },