Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/desktop/src/preview/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,28 @@ describe("PreviewManager", () => {
expect(focus).toHaveBeenCalledOnce();
expect(send).toHaveBeenCalledTimes(2);
send.mockClear();
focus.mockClear();
yield* manager.setForwardedShortcuts([
{ command: "rightPanel.nextSurface", shortcut: parseKeybindingShortcut("ctrl+tab")! },
]);
beforeInput(
{ preventDefault: vi.fn() } as never,
{
type: "keyDown",
key: "Tab",
meta: false,
control: true,
shift: false,
alt: false,
} as never,
);
expect(focus).toHaveBeenCalledOnce();
expect(send).toHaveBeenCalledExactlyOnceWith(
"desktop:menu-action",
"rightPanel.nextSurface",
);
expect(focus.mock.invocationCallOrder[0]).toBeLessThan(send.mock.invocationCallOrder[0]!);
send.mockClear();
yield* manager.setForwardedShortcuts([{ command: "view.reopenClosed", shortcut }]);

Object.assign(newer.webContents, { focusedFrame: null });
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
if (
forwarded.command === "workspace.focusNext" ||
forwarded.command === "workspace.focusPrevious" ||
forwarded.command === "rightPanel.nextSurface" ||
forwarded.command === "rightPanel.previousSurface" ||
forwarded.command === "preview.focusUrl"
) {
// DOM focus in the renderer cannot by itself release the guest's native keyboard focus.
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/ReopenClosedViewShortcut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const PREVIEW_FORWARDED_COMMANDS = [
"rightPanel.toggleMaximized",
"rightPanel.new",
"rightPanel.close",
"rightPanel.nextSurface",
"rightPanel.previousSurface",
"preview.focusUrl",
"preview.zoomIn",
"preview.zoomOut",
Expand Down
66 changes: 65 additions & 1 deletion apps/web/src/components/RightPanelTabs.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import "~/index.css";

import { EnvironmentId } from "@t3tools/contracts";
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
import { useState } from "react";
import { describe, expect, it, vi } from "vite-plus/test";
import { userEvent } from "vite-plus/test/browser";

import { InputGroup, InputGroupAddon, InputGroupInput } from "~/components/ui/input-group";
import type { RightPanelSurface } from "~/rightPanelStore";
import { render, stubGlobal } from "../../test/render";
import { dispatchMenuAction } from "~/shortcuts/dispatcher";
import { act, render, stubGlobal } from "../../test/render";
import { HistorySwipeNavigation } from "./HistorySwipeNavigation";
import { RightPanelTabs, type RightPanelTabsProps } from "./RightPanelTabs";
import { subscribePreviewAction } from "./preview/previewActionBus";
Expand Down Expand Up @@ -222,6 +225,67 @@ function releaseThumbButton(
};
}

const FILES_SURFACE: RightPanelSurface = { id: "files", kind: "files" };

function CyclingPanel(props: {
active: RightPanelSurface;
surfaces: readonly RightPanelSurface[];
}) {
const [activeId, setActiveId] = useState(props.active.id);
const base = panel(props.active).props as RightPanelTabsProps;
return (
<RightPanelTabs
{...base}
keybindings={DEFAULT_RESOLVED_KEYBINDINGS}
surfaces={props.surfaces}
activeSurfaceId={activeId}
onActivate={(surface) => setActiveId(surface.id)}
>
{null}
</RightPanelTabs>
);
}

describe("surface switching", () => {
it("cycles panel surfaces forwards with Ctrl+Tab and backwards with Ctrl+Shift+Tab", async () => {
await using screen = await render(
<CyclingPanel
active={BROWSER_SURFACE}
surfaces={[BROWSER_SURFACE, DIFF_SURFACE, FILES_SURFACE]}
/>,
);
const expectActiveTab = (title: string) =>
vi.waitFor(() => {
expect(screen.container.querySelector("[data-active-tab='true']")?.textContent).toBe(title);
});

await expectActiveTab("Browser");
await userEvent.keyboard("{Control>}{Tab}{/Control}");
await expectActiveTab("Diff");
await userEvent.keyboard("{Control>}{Tab}{/Control}");
await expectActiveTab("Files");
await userEvent.keyboard("{Control>}{Tab}{/Control}");
await expectActiveTab("Browser");
await userEvent.keyboard("{Control>}{Shift>}{Tab}{/Shift}{/Control}");
await expectActiveTab("Files");
});

it("cycles when desktop forwards the chord from a focused browser page", async () => {
await using screen = await render(
<CyclingPanel active={BROWSER_SURFACE} surfaces={[BROWSER_SURFACE, DIFF_SURFACE]} />,
);
const expectActiveTab = (title: string) =>
vi.waitFor(() => {
expect(screen.container.querySelector("[data-active-tab='true']")?.textContent).toBe(title);
});

await act(() => dispatchMenuAction("rightPanel.nextSurface"));
await expectActiveTab("Diff");
await act(() => dispatchMenuAction("rightPanel.previousSurface"));
await expectActiveTab("Browser");
});
});

const STAYS_PUT = { focusMoved: false, routerMoved: false };

describe("right panel thumb buttons", () => {
Expand Down
45 changes: 36 additions & 9 deletions apps/web/src/components/RightPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
import { observeResize } from "~/lib/observeResize";
import { surfaceShortcutKey } from "~/lib/surfaceShortcutKey";
import { registerMenuAction } from "~/shortcuts/dispatcher";

export interface RightPanelTabsProps {
mode: PreviewPanelMode;
Expand Down Expand Up @@ -1142,14 +1143,31 @@ export function RightPanelTabs(props: RightPanelTabsProps) {

const addSurfaceMenuBlocked = () =>
!addSurfaceMenuOpen && document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS) !== null;
const onNewSurfaceKeyDown = useEffectEvent((event: KeyboardEvent) => {
const cycleRightPanelSurface = useEffectEvent((direction: 1 | -1) => {
if (props.surfaces.length < 2) return;
const activeIndex = props.surfaces.findIndex((surface) => surface.id === props.activeSurfaceId);
const nextIndex =
activeIndex === -1
? direction === 1
? 0
: props.surfaces.length - 1
: (activeIndex + direction + props.surfaces.length) % props.surfaces.length;
const next = props.surfaces[nextIndex];
if (next) props.onActivate(next);
});
const onPanelKeyDown = useEffectEvent((event: KeyboardEvent) => {
if (event.defaultPrevented || event.isComposing) return;
if (
resolveShortcutCommand(event, props.keybindings, {
context: { ...props.getShortcutContext(), rightPanelOpen: true },
}) !== "rightPanel.new"
)
const command = resolveShortcutCommand(event, props.keybindings, {
context: { ...props.getShortcutContext(), rightPanelOpen: true },
});
if (command === "rightPanel.nextSurface" || command === "rightPanel.previousSurface") {
if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
event.preventDefault();
event.stopPropagation();
cycleRightPanelSurface(command === "rightPanel.nextSurface" ? 1 : -1);
return;
}
if (command !== "rightPanel.new") return;
if (addSurfaceMenuBlocked()) return;
event.preventDefault();
event.stopPropagation();
Expand All @@ -1163,14 +1181,23 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
const onMenuAction = useEffectEvent((action: string) => {
if (action === "rightPanel.new" && !addSurfaceMenuBlocked()) setAddSurfaceMenuOpen(true);
});
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes document keydown and the desktop menu action (forwarded from a focused browser page) for the new surface shortcut while the panel is open
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes document keydown and desktop menu actions forwarded from a focused browser page while the panel is open
useEffect(() => {
if (props.open === false) return;
document.addEventListener("keydown", onNewSurfaceKeyDown, true);
document.addEventListener("keydown", onPanelKeyDown, true);
const unsubscribe = window.desktopBridge?.onMenuAction(onMenuAction);
const unregister = [
registerMenuAction("rightPanel.nextSurface", () => {
if (!document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) cycleRightPanelSurface(1);
}),
registerMenuAction("rightPanel.previousSurface", () => {
if (!document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) cycleRightPanelSurface(-1);
}),
];
return () => {
document.removeEventListener("keydown", onNewSurfaceKeyDown, true);
document.removeEventListener("keydown", onPanelKeyDown, true);
unsubscribe?.();
for (const cleanup of unregister) cleanup();
};
}, [props.open]);

Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/files/BrowserDocumentFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const HTML_RENDER_SHORTCUT_COMMANDS: ReadonlySet<KeybindingCommand> = new Set([
"sidebar.toggle",
"rightPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.nextSurface",
"rightPanel.previousSurface",
"threadPanel.toggle",
"terminal.toggle",
"preview.toggle",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/settings/KeybindingsSettings.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ const COMMAND_LABELS: Partial<Record<KeybindingCommand, string>> = {
"terminal.close": msg("Terminal: Close"),
"rightPanel.toggle": msg("Right Panel: Toggle"),
"rightPanel.new": msg("Right Panel: New"),
"rightPanel.nextSurface": msg("Right Panel: Next Surface"),
"rightPanel.previousSurface": msg("Right Panel: Previous Surface"),
"threadPanel.toggle": msg("Thread Panel: Toggle"),
"rightPanel.toggleMaximized": msg("Right Panel: Toggle Maximized"),
"rightPanel.close": msg("Right Panel: Close"),
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8783,6 +8783,8 @@
"16dfd6305f3951a3": "Terminal: Schließen",
"0e54f664e6fdc156": "Rechter Bereich: Umschalten",
"81e0e9f4304d2f01": "Rechter Bereich: Neu",
"c697b32317def3e9": "Rechter Bereich: Nächste Ansicht",
"cccbfceba87d6c2d": "Rechter Bereich: Vorherige Ansicht",
"afdfe975da764288": "Thread-Bereich: Umschalten",
"329fd01696d446b8": "Rechter Bereich: Maximieren umschalten",
"97c7de6aaab317a2": "Rechter Bereich: Schließen",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8791,6 +8791,8 @@
"16dfd6305f3951a3": "Terminal: Close",
"0e54f664e6fdc156": "Right Panel: Toggle",
"81e0e9f4304d2f01": "Right Panel: New",
"c697b32317def3e9": "Right Panel: Next Surface",
"cccbfceba87d6c2d": "Right Panel: Previous Surface",
"afdfe975da764288": "Thread Panel: Toggle",
"329fd01696d446b8": "Right Panel: Toggle Maximized",
"97c7de6aaab317a2": "Right Panel: Close",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -8781,6 +8781,8 @@
"16dfd6305f3951a3": "Terminal: cerrar",
"0e54f664e6fdc156": "Panel derecho: alternar",
"81e0e9f4304d2f01": "Panel derecho: nuevo",
"c697b32317def3e9": "Panel derecho: vista siguiente",
"cccbfceba87d6c2d": "Panel derecho: vista anterior",
"afdfe975da764288": "Panel del hilo: alternar",
"329fd01696d446b8": "Panel derecho: alternar maximizado",
"97c7de6aaab317a2": "Panel derecho: cerrar",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -8782,6 +8782,8 @@
"16dfd6305f3951a3": "Terminal : fermer",
"0e54f664e6fdc156": "Panneau de droite : afficher/masquer",
"81e0e9f4304d2f01": "Panneau de droite : nouveau",
"c697b32317def3e9": "Panneau de droite : surface suivante",
"cccbfceba87d6c2d": "Panneau de droite : surface précédente",
"afdfe975da764288": "Panneau du fil : afficher/masquer",
"329fd01696d446b8": "Panneau de droite : agrandir/restaurer",
"97c7de6aaab317a2": "Panneau de droite : fermer",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -8739,6 +8739,8 @@
"16dfd6305f3951a3": "ターミナル: 閉じる",
"0e54f664e6fdc156": "右パネル: 切り替え",
"81e0e9f4304d2f01": "右パネル: 新規",
"c697b32317def3e9": "右パネル: 次のサーフェス",
"cccbfceba87d6c2d": "右パネル: 前のサーフェス",
"afdfe975da764288": "スレッドパネル: 切り替え",
"329fd01696d446b8": "右パネル: 最大化の切り替え",
"97c7de6aaab317a2": "右パネル: 閉じる",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -8742,6 +8742,8 @@
"16dfd6305f3951a3": "터미널: 닫기",
"0e54f664e6fdc156": "오른쪽 패널: 전환",
"81e0e9f4304d2f01": "오른쪽 패널: 새로 만들기",
"c697b32317def3e9": "오른쪽 패널: 다음 화면",
"cccbfceba87d6c2d": "오른쪽 패널: 이전 화면",
"afdfe975da764288": "스레드 패널: 전환",
"329fd01696d446b8": "오른쪽 패널: 최대화 전환",
"97c7de6aaab317a2": "오른쪽 패널: 닫기",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -8781,6 +8781,8 @@
"16dfd6305f3951a3": "Terminal: fechar",
"0e54f664e6fdc156": "Painel direito: alternar",
"81e0e9f4304d2f01": "Painel direito: novo",
"c697b32317def3e9": "Painel direito: próxima superfície",
"cccbfceba87d6c2d": "Painel direito: superfície anterior",
"afdfe975da764288": "Painel da thread: alternar",
"329fd01696d446b8": "Painel direito: alternar maximizado",
"97c7de6aaab317a2": "Painel direito: fechar",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -8783,6 +8783,8 @@
"16dfd6305f3951a3": "Терминал: закрыть",
"0e54f664e6fdc156": "Правая панель: показать/скрыть",
"81e0e9f4304d2f01": "Правая панель: новая",
"c697b32317def3e9": "Правая панель: следующая вкладка",
"cccbfceba87d6c2d": "Правая панель: предыдущая вкладка",
"afdfe975da764288": "Панель треда: показать/скрыть",
"329fd01696d446b8": "Правая панель: развернуть/свернуть",
"97c7de6aaab317a2": "Правая панель: закрыть",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -8789,6 +8789,8 @@
"16dfd6305f3951a3": "Terminal: stäng",
"0e54f664e6fdc156": "Högerpanel: växla",
"81e0e9f4304d2f01": "Högerpanel: ny",
"c697b32317def3e9": "Högerpanel: nästa yta",
"cccbfceba87d6c2d": "Högerpanel: föregående yta",
"afdfe975da764288": "Trådpanel: växla",
"329fd01696d446b8": "Högerpanel: växla maximerad",
"97c7de6aaab317a2": "Högerpanel: stäng",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -8799,6 +8799,8 @@
"16dfd6305f3951a3": "终端:关闭",
"0e54f664e6fdc156": "右侧面板:切换显示",
"81e0e9f4304d2f01": "右侧面板:新建",
"c697b32317def3e9": "右侧面板:下一个标签页",
"cccbfceba87d6c2d": "右侧面板:上一个标签页",
"afdfe975da764288": "会话面板:切换显示",
"329fd01696d446b8": "右侧面板:切换最大化",
"97c7de6aaab317a2": "右侧面板:关闭",
Expand Down
4 changes: 4 additions & 0 deletions docs/user/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ 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.

## Switch right panel surfaces

With the right panel open, `Ctrl+Tab` moves to the next surface and `Ctrl+Shift+Tab` moves to the previous surface. Both wrap at either end. Browsers reserve those chords for browser tabs, so they only reach the desktop app. To use them in a browser tab, bind other keys for **Right Panel: Next Surface** and **Right Panel: Previous Surface** in Settings → Keybindings.

## Copy pull request references

With a PR open in the right panel or on the Pull requests page, use `mod+shift+c`
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const STATIC_KEYBINDING_COMMANDS = [
"terminal.close",
"rightPanel.toggle",
"rightPanel.new",
"rightPanel.nextSurface",
"rightPanel.previousSurface",
"threadPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.close",
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ key: "mod+alt+b", command: "rightPanel.toggle" },
{ key: "mod+shift+b", command: "threadPanel.toggle", when: "!terminalFocus" },
{ key: "mod+t", command: "rightPanel.new", when: "rightPanelOpen && !terminalFocus" },
// Browsers keep Ctrl+Tab for their own tabs, so this default only reaches the desktop app or a
// standalone browser window; everywhere else it is inert rather than harmful.
{ key: "ctrl+tab", command: "rightPanel.nextSurface", when: "rightPanelOpen" },
{ key: "ctrl+shift+tab", command: "rightPanel.previousSurface", when: "rightPanelOpen" },
{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },
{ key: "mod+shift+d", command: "terminal.splitVertical", when: "terminalFocus" },
{ key: "mod+shift+d", command: "composer.dictation", when: "!terminalFocus" },
Expand Down
Loading