diff --git a/apps/desktop/src/preview/Manager.test.ts b/apps/desktop/src/preview/Manager.test.ts index 9c15a0e0a4a9..1bad4a8ed8e1 100644 --- a/apps/desktop/src/preview/Manager.test.ts +++ b/apps/desktop/src/preview/Manager.test.ts @@ -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 }); diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts index 531e269a07f1..b1e17f42542a 100644 --- a/apps/desktop/src/preview/Manager.ts +++ b/apps/desktop/src/preview/Manager.ts @@ -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. diff --git a/apps/web/src/components/ReopenClosedViewShortcut.tsx b/apps/web/src/components/ReopenClosedViewShortcut.tsx index 1bc9d62a20c8..90a05c8846b9 100644 --- a/apps/web/src/components/ReopenClosedViewShortcut.tsx +++ b/apps/web/src/components/ReopenClosedViewShortcut.tsx @@ -63,6 +63,8 @@ const PREVIEW_FORWARDED_COMMANDS = [ "rightPanel.toggleMaximized", "rightPanel.new", "rightPanel.close", + "rightPanel.nextSurface", + "rightPanel.previousSurface", "preview.focusUrl", "preview.zoomIn", "preview.zoomOut", diff --git a/apps/web/src/components/RightPanelTabs.browser.test.tsx b/apps/web/src/components/RightPanelTabs.browser.test.tsx index 347971993c7c..dbeb4dd47215 100644 --- a/apps/web/src/components/RightPanelTabs.browser.test.tsx +++ b/apps/web/src/components/RightPanelTabs.browser.test.tsx @@ -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"; @@ -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 ( + setActiveId(surface.id)} + > + {null} + + ); +} + +describe("surface switching", () => { + it("cycles panel surfaces forwards with Ctrl+Tab and backwards with Ctrl+Shift+Tab", async () => { + await using screen = await render( + , + ); + 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( + , + ); + 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", () => { diff --git a/apps/web/src/components/RightPanelTabs.tsx b/apps/web/src/components/RightPanelTabs.tsx index 57ed98c49dfc..447595b9f818 100644 --- a/apps/web/src/components/RightPanelTabs.tsx +++ b/apps/web/src/components/RightPanelTabs.tsx @@ -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; @@ -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(); @@ -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]); diff --git a/apps/web/src/components/files/BrowserDocumentFrame.tsx b/apps/web/src/components/files/BrowserDocumentFrame.tsx index 3270556fb0ff..1dafceeb5726 100644 --- a/apps/web/src/components/files/BrowserDocumentFrame.tsx +++ b/apps/web/src/components/files/BrowserDocumentFrame.tsx @@ -64,6 +64,8 @@ const HTML_RENDER_SHORTCUT_COMMANDS: ReadonlySet = new Set([ "sidebar.toggle", "rightPanel.toggle", "rightPanel.toggleMaximized", + "rightPanel.nextSurface", + "rightPanel.previousSurface", "threadPanel.toggle", "terminal.toggle", "preview.toggle", diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.ts index 9d03b7ab72e4..ccc4e600c08b 100644 --- a/apps/web/src/components/settings/KeybindingsSettings.logic.ts +++ b/apps/web/src/components/settings/KeybindingsSettings.logic.ts @@ -457,6 +457,8 @@ const COMMAND_LABELS: Partial> = { "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"), diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 7900e7318609..0f3b50c0f92b 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -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", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 5bdd7c383d31..5177a5f225aa 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -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", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 91dbb2b07f50..110de18a8b0f 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -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", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index f5cf7e62a474..33df7c995857 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -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", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 7e3be343b068..b63ac8c93ff4 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -8739,6 +8739,8 @@ "16dfd6305f3951a3": "ターミナル: 閉じる", "0e54f664e6fdc156": "右パネル: 切り替え", "81e0e9f4304d2f01": "右パネル: 新規", + "c697b32317def3e9": "右パネル: 次のサーフェス", + "cccbfceba87d6c2d": "右パネル: 前のサーフェス", "afdfe975da764288": "スレッドパネル: 切り替え", "329fd01696d446b8": "右パネル: 最大化の切り替え", "97c7de6aaab317a2": "右パネル: 閉じる", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index ef69858aead1..a0760887ea12 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -8742,6 +8742,8 @@ "16dfd6305f3951a3": "터미널: 닫기", "0e54f664e6fdc156": "오른쪽 패널: 전환", "81e0e9f4304d2f01": "오른쪽 패널: 새로 만들기", + "c697b32317def3e9": "오른쪽 패널: 다음 화면", + "cccbfceba87d6c2d": "오른쪽 패널: 이전 화면", "afdfe975da764288": "스레드 패널: 전환", "329fd01696d446b8": "오른쪽 패널: 최대화 전환", "97c7de6aaab317a2": "오른쪽 패널: 닫기", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 5b2f82a27a41..90ea7b09da49 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -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", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 2891cb8165d7..2c5a368d91f8 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -8783,6 +8783,8 @@ "16dfd6305f3951a3": "Терминал: закрыть", "0e54f664e6fdc156": "Правая панель: показать/скрыть", "81e0e9f4304d2f01": "Правая панель: новая", + "c697b32317def3e9": "Правая панель: следующая вкладка", + "cccbfceba87d6c2d": "Правая панель: предыдущая вкладка", "afdfe975da764288": "Панель треда: показать/скрыть", "329fd01696d446b8": "Правая панель: развернуть/свернуть", "97c7de6aaab317a2": "Правая панель: закрыть", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index c792d6fb4a98..c74bbc09b316 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -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", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index cd80e9a35102..cde98eadf363 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -8799,6 +8799,8 @@ "16dfd6305f3951a3": "终端:关闭", "0e54f664e6fdc156": "右侧面板:切换显示", "81e0e9f4304d2f01": "右侧面板:新建", + "c697b32317def3e9": "右侧面板:下一个标签页", + "cccbfceba87d6c2d": "右侧面板:上一个标签页", "afdfe975da764288": "会话面板:切换显示", "329fd01696d446b8": "右侧面板:切换最大化", "97c7de6aaab317a2": "右侧面板:关闭", diff --git a/docs/user/keybindings.md b/docs/user/keybindings.md index eab9e88ec98f..32d1377ede30 100644 --- a/docs/user/keybindings.md +++ b/docs/user/keybindings.md @@ -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` diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts index eda5138b760b..ac7b2758097e 100644 --- a/packages/contracts/src/keybindings.ts +++ b/packages/contracts/src/keybindings.ts @@ -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", diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.ts index 3d9fcc0727d3..9ae163c8213b 100644 --- a/packages/shared/src/keybindings.ts +++ b/packages/shared/src/keybindings.ts @@ -68,6 +68,10 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray = [ { 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" },