From f0250d5614c7f606c0636d65b91fd0e25c3654e7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 13:59:43 +0000 Subject: [PATCH 1/5] test(web): Cmd+T from a focused browser page reaches the right panel Repro for #39728: rightPanel.new is not forwarded from a focused desktop browser page, so Cmd/Ctrl+T there does nothing. Co-Authored-By: Claude Opus 5.5 --- .../src/components/ReopenClosedViewShortcut.browser.test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ReopenClosedViewShortcut.browser.test.tsx b/apps/web/src/components/ReopenClosedViewShortcut.browser.test.tsx index 0830d218945ab..406e3d79bd57d 100644 --- a/apps/web/src/components/ReopenClosedViewShortcut.browser.test.tsx +++ b/apps/web/src/components/ReopenClosedViewShortcut.browser.test.tsx @@ -265,7 +265,7 @@ describe("root reopen shortcut", () => { expect(useClosedViewStore.getState().entries).toEqual([]); }, ); - it("forwards address-bar focus, zoom, and panel close from a focused desktop page", async () => { + it("forwards address-bar focus, zoom, and panel new and close from a focused desktop page", async () => { setup(); await using _shortcut = await renderShortcut(); expect(state.setShortcuts).toHaveBeenLastCalledWith( @@ -275,6 +275,7 @@ describe("root reopen shortcut", () => { "preview.zoomIn", "preview.zoomOut", "preview.resetZoom", + "rightPanel.new", "rightPanel.close", ].map((command) => expect.objectContaining({ command })), ), From 796ff4e31b09e70b018fef5bbb246957042d6ff9 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 14:07:20 +0000 Subject: [PATCH 2/5] fix(web): Cmd/Ctrl+T from a focused Browser page opens the new-tab menu The desktop shell only forwards shortcuts on the preview forward list from a focused guest page. rightPanel.new was missing from it, its `when` clause needed rightPanelOpen in the forwarding context, and RightPanelTabs only listened on the host document. Forward the chord, open the + menu on the menu action, and hand native keyboard focus back to the host so the guest does not keep it under the open menu. Fixes pingdotgg/t3code#39728 Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/preview/Manager.ts | 3 ++- .../components/ReopenClosedViewShortcut.tsx | 2 ++ .../RightPanelTabs.browser.test.tsx | 6 +++++- apps/web/src/components/RightPanelTabs.tsx | 21 +++++++++++++------ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts index 1f28826bcc196..3384dc3bf74ef 100644 --- a/apps/desktop/src/preview/Manager.ts +++ b/apps/desktop/src/preview/Manager.ts @@ -1606,7 +1606,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function if ( forwarded.command === "workspace.focusNext" || forwarded.command === "workspace.focusPrevious" || - forwarded.command === "preview.focusUrl" + forwarded.command === "preview.focusUrl" || + forwarded.command === "rightPanel.new" ) { // DOM focus in the renderer cannot by itself release the guest's native keyboard focus. host.focus(); diff --git a/apps/web/src/components/ReopenClosedViewShortcut.tsx b/apps/web/src/components/ReopenClosedViewShortcut.tsx index 8c4e7d7c5a80c..83e0d3deaf990 100644 --- a/apps/web/src/components/ReopenClosedViewShortcut.tsx +++ b/apps/web/src/components/ReopenClosedViewShortcut.tsx @@ -54,6 +54,7 @@ const PREVIEW_FORWARDED_COMMANDS = [ "sidebar.toggle", "rightPanel.toggle", "rightPanel.toggleMaximized", + "rightPanel.new", "rightPanel.close", "preview.focusUrl", "preview.zoomIn", @@ -211,6 +212,7 @@ export function ReopenClosedViewShortcut() { context: { previewFocus: true, previewOpen: true, + rightPanelOpen: true, terminalFocus: false, terminalOpen, editableFocus: false, diff --git a/apps/web/src/components/RightPanelTabs.browser.test.tsx b/apps/web/src/components/RightPanelTabs.browser.test.tsx index f803cb41520bc..515d5cdbfb32b 100644 --- a/apps/web/src/components/RightPanelTabs.browser.test.tsx +++ b/apps/web/src/components/RightPanelTabs.browser.test.tsx @@ -25,7 +25,11 @@ function trackpad() { }; let scrolling = false; return { - bridge: { onTrackpadScrollBegin: subscribe(begin), onTrackpadScrollEnd: subscribe(end) }, + bridge: { + onTrackpadScrollBegin: subscribe(begin), + onTrackpadScrollEnd: subscribe(end), + onMenuAction: () => () => {}, + }, scroll(target: Element, deltas: readonly number[]) { let scroller: Element | null = target; while ( diff --git a/apps/web/src/components/RightPanelTabs.tsx b/apps/web/src/components/RightPanelTabs.tsx index 2ce8f22f63f5e..f59ba6d9fc4fc 100644 --- a/apps/web/src/components/RightPanelTabs.tsx +++ b/apps/web/src/components/RightPanelTabs.tsx @@ -1117,6 +1117,10 @@ export function RightPanelTabs(props: RightPanelTabsProps) { if (props.open === false && addSurfaceMenuOpen) setAddSurfaceMenuOpen(false); + const openAddSurfaceMenu = useEffectEvent(() => { + addSurfaceTriggerRef.current?.focus(); + setAddSurfaceMenuOpen(true); + }); const onNewSurfaceKeyDown = useEffectEvent((event: KeyboardEvent) => { if (event.defaultPrevented || event.isComposing) return; if ( @@ -1128,16 +1132,21 @@ export function RightPanelTabs(props: RightPanelTabsProps) { if (!addSurfaceMenuOpen && document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return; event.preventDefault(); event.stopPropagation(); - if (!event.repeat) { - addSurfaceTriggerRef.current?.focus(); - setAddSurfaceMenuOpen(true); - } + if (!event.repeat) openAddSurfaceMenu(); }); - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a document keydown listener for the new surface shortcut while the panel is open + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a document keydown listener and the desktop menu action for the new surface shortcut while the panel is open useEffect(() => { if (props.open === false) return; document.addEventListener("keydown", onNewSurfaceKeyDown, true); - return () => document.removeEventListener("keydown", onNewSurfaceKeyDown, true); + // A focused desktop browser page forwards the chord as a menu action. + const unsubscribe = window.desktopBridge?.onMenuAction((action) => { + if (action === "rightPanel.new" && !document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) + openAddSurfaceMenu(); + }); + return () => { + document.removeEventListener("keydown", onNewSurfaceKeyDown, true); + unsubscribe?.(); + }; }, [props.open]); const updateTabScrollState = (viewport: HTMLDivElement) => { From d306d937eb123fa80d3b3db6b5ce46d2be9c0d59 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 14:16:17 +0000 Subject: [PATCH 3/5] fix(web): clicking + after using a Browser page keeps the menu open The Browser webview dismissed host popups on every `focus` event. When the host window is activated again after the page held focus, Chromium sends `focus` to the window and then to the still-focused webview, which closed the + menu the same click had just opened. Skip that refocus; a real move of focus into the page, and presses reported by the guest preload, still dismiss host popups. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/browser/HostedBrowserWebview.tsx | 5 +-- .../src/browser/webviewFocusDismissal.test.ts | 29 +++++++++++++++++ apps/web/src/browser/webviewFocusDismissal.ts | 32 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 apps/web/src/browser/webviewFocusDismissal.test.ts create mode 100644 apps/web/src/browser/webviewFocusDismissal.ts diff --git a/apps/web/src/browser/HostedBrowserWebview.tsx b/apps/web/src/browser/HostedBrowserWebview.tsx index 023fb03c3aa17..572b62813c4e4 100644 --- a/apps/web/src/browser/HostedBrowserWebview.tsx +++ b/apps/web/src/browser/HostedBrowserWebview.tsx @@ -30,6 +30,7 @@ import { resolveHostedBrowserWebviewWrapperStyle } from "./hostedBrowserWebviewS import { usePreviewWebviewConfig } from "./previewWebviewConfigState"; import { useBrowserLayoutZoomFactor } from "./useBrowserLayoutZoomFactor"; import { useBrowserViewportResize } from "./useBrowserViewportResize"; +import { subscribeWebviewFocusDismissal } from "./webviewFocusDismissal"; import { INITIAL_WEBVIEW_CRASH_RECOVERY_STATE, planWebviewCrashRecovery, @@ -201,7 +202,7 @@ export function HostedBrowserWebview(props: { webview.addEventListener("did-attach", register); webview.addEventListener("dom-ready", register); webview.addEventListener("render-process-gone", recoverGuest); - webview.addEventListener("focus", dismissHostPopups); + const unsubscribeFocus = subscribeWebviewFocusDismissal(window, webview, dismissHostPopups); webview.addEventListener("ipc-message", guestPointerDown); register(); return () => { @@ -210,7 +211,7 @@ export function HostedBrowserWebview(props: { webview.removeEventListener("did-attach", register); webview.removeEventListener("dom-ready", register); webview.removeEventListener("render-process-gone", recoverGuest); - webview.removeEventListener("focus", dismissHostPopups); + unsubscribeFocus(); webview.removeEventListener("ipc-message", guestPointerDown); }; }, [ diff --git a/apps/web/src/browser/webviewFocusDismissal.test.ts b/apps/web/src/browser/webviewFocusDismissal.test.ts new file mode 100644 index 0000000000000..d193985b4226e --- /dev/null +++ b/apps/web/src/browser/webviewFocusDismissal.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, it, vi } from "vite-plus/test"; + +import { subscribeWebviewFocusDismissal } from "./webviewFocusDismissal"; + +describe("subscribeWebviewFocusDismissal", () => { + it("dismisses host popups when focus moves into the page, not when the host window refocuses it", () => { + vi.useFakeTimers(); + const host = new EventTarget(); + const webview = new EventTarget(); + const dismiss = vi.fn(); + const unsubscribe = subscribeWebviewFocusDismissal(host, webview, dismiss); + try { + webview.dispatchEvent(new Event("focus")); + expect(dismiss).toHaveBeenCalledOnce(); + + host.dispatchEvent(new Event("focus")); + webview.dispatchEvent(new Event("focus")); + expect(dismiss).toHaveBeenCalledOnce(); + + host.dispatchEvent(new Event("focus")); + vi.runAllTimers(); + webview.dispatchEvent(new Event("focus")); + expect(dismiss).toHaveBeenCalledTimes(2); + } finally { + unsubscribe(); + vi.useRealTimers(); + } + }); +}); diff --git a/apps/web/src/browser/webviewFocusDismissal.ts b/apps/web/src/browser/webviewFocusDismissal.ts new file mode 100644 index 0000000000000..f920bf674b0fa --- /dev/null +++ b/apps/web/src/browser/webviewFocusDismissal.ts @@ -0,0 +1,32 @@ +/** + * Calls `dismiss` when focus moves into the webview. Chromium refocuses an already focused + * webview right after the host window's own `focus` event when the host is reactivated, such + * as by a click on host UI after typing in the page; that is not a press into the page. + */ +export function subscribeWebviewFocusDismissal( + host: EventTarget, + webview: EventTarget, + dismiss: () => void, +): () => void { + let hostRefocusing = false; + let reset: ReturnType | undefined; + const onHostFocus = (event: Event) => { + if (event.target !== host) return; + hostRefocusing = true; + clearTimeout(reset); + reset = setTimeout(() => { + hostRefocusing = false; + }); + }; + const onWebviewFocus = () => { + if (!hostRefocusing) dismiss(); + hostRefocusing = false; + }; + host.addEventListener("focus", onHostFocus); + webview.addEventListener("focus", onWebviewFocus); + return () => { + clearTimeout(reset); + host.removeEventListener("focus", onHostFocus); + webview.removeEventListener("focus", onWebviewFocus); + }; +} From 14117b0ebbbf500399b8d67347817e955b44b505 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 15:16:18 +0000 Subject: [PATCH 4/5] fix(web): returning to the window no longer closes a menu that just opened When the app window regains focus, ChatView refocuses the composer two frames later unless focus is somewhere that owns it. An open menu trigger was not on that list, so the + menu opened by Cmd/Ctrl+T from a Browser page (or by a click that reactivates the window before the popup takes focus) lost focus to the composer and closed. Keep focus on a control whose popup is open. This replaces the webview focus-dismissal change: a real run showed the composer refocus, not the webview focus event, closing the menu. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/browser/HostedBrowserWebview.tsx | 5 ++- .../src/browser/webviewFocusDismissal.test.ts | 29 ----------------- apps/web/src/browser/webviewFocusDismissal.ts | 32 ------------------- .../components/ChatView.logic.browser.test.ts | 12 +++++++ apps/web/src/components/ChatView.logic.ts | 2 +- 5 files changed, 15 insertions(+), 65 deletions(-) delete mode 100644 apps/web/src/browser/webviewFocusDismissal.test.ts delete mode 100644 apps/web/src/browser/webviewFocusDismissal.ts diff --git a/apps/web/src/browser/HostedBrowserWebview.tsx b/apps/web/src/browser/HostedBrowserWebview.tsx index 572b62813c4e4..023fb03c3aa17 100644 --- a/apps/web/src/browser/HostedBrowserWebview.tsx +++ b/apps/web/src/browser/HostedBrowserWebview.tsx @@ -30,7 +30,6 @@ import { resolveHostedBrowserWebviewWrapperStyle } from "./hostedBrowserWebviewS import { usePreviewWebviewConfig } from "./previewWebviewConfigState"; import { useBrowserLayoutZoomFactor } from "./useBrowserLayoutZoomFactor"; import { useBrowserViewportResize } from "./useBrowserViewportResize"; -import { subscribeWebviewFocusDismissal } from "./webviewFocusDismissal"; import { INITIAL_WEBVIEW_CRASH_RECOVERY_STATE, planWebviewCrashRecovery, @@ -202,7 +201,7 @@ export function HostedBrowserWebview(props: { webview.addEventListener("did-attach", register); webview.addEventListener("dom-ready", register); webview.addEventListener("render-process-gone", recoverGuest); - const unsubscribeFocus = subscribeWebviewFocusDismissal(window, webview, dismissHostPopups); + webview.addEventListener("focus", dismissHostPopups); webview.addEventListener("ipc-message", guestPointerDown); register(); return () => { @@ -211,7 +210,7 @@ export function HostedBrowserWebview(props: { webview.removeEventListener("did-attach", register); webview.removeEventListener("dom-ready", register); webview.removeEventListener("render-process-gone", recoverGuest); - unsubscribeFocus(); + webview.removeEventListener("focus", dismissHostPopups); webview.removeEventListener("ipc-message", guestPointerDown); }; }, [ diff --git a/apps/web/src/browser/webviewFocusDismissal.test.ts b/apps/web/src/browser/webviewFocusDismissal.test.ts deleted file mode 100644 index d193985b4226e..0000000000000 --- a/apps/web/src/browser/webviewFocusDismissal.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { describe, expect, it, vi } from "vite-plus/test"; - -import { subscribeWebviewFocusDismissal } from "./webviewFocusDismissal"; - -describe("subscribeWebviewFocusDismissal", () => { - it("dismisses host popups when focus moves into the page, not when the host window refocuses it", () => { - vi.useFakeTimers(); - const host = new EventTarget(); - const webview = new EventTarget(); - const dismiss = vi.fn(); - const unsubscribe = subscribeWebviewFocusDismissal(host, webview, dismiss); - try { - webview.dispatchEvent(new Event("focus")); - expect(dismiss).toHaveBeenCalledOnce(); - - host.dispatchEvent(new Event("focus")); - webview.dispatchEvent(new Event("focus")); - expect(dismiss).toHaveBeenCalledOnce(); - - host.dispatchEvent(new Event("focus")); - vi.runAllTimers(); - webview.dispatchEvent(new Event("focus")); - expect(dismiss).toHaveBeenCalledTimes(2); - } finally { - unsubscribe(); - vi.useRealTimers(); - } - }); -}); diff --git a/apps/web/src/browser/webviewFocusDismissal.ts b/apps/web/src/browser/webviewFocusDismissal.ts deleted file mode 100644 index f920bf674b0fa..0000000000000 --- a/apps/web/src/browser/webviewFocusDismissal.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Calls `dismiss` when focus moves into the webview. Chromium refocuses an already focused - * webview right after the host window's own `focus` event when the host is reactivated, such - * as by a click on host UI after typing in the page; that is not a press into the page. - */ -export function subscribeWebviewFocusDismissal( - host: EventTarget, - webview: EventTarget, - dismiss: () => void, -): () => void { - let hostRefocusing = false; - let reset: ReturnType | undefined; - const onHostFocus = (event: Event) => { - if (event.target !== host) return; - hostRefocusing = true; - clearTimeout(reset); - reset = setTimeout(() => { - hostRefocusing = false; - }); - }; - const onWebviewFocus = () => { - if (!hostRefocusing) dismiss(); - hostRefocusing = false; - }; - host.addEventListener("focus", onHostFocus); - webview.addEventListener("focus", onWebviewFocus); - return () => { - clearTimeout(reset); - host.removeEventListener("focus", onHostFocus); - webview.removeEventListener("focus", onWebviewFocus); - }; -} diff --git a/apps/web/src/components/ChatView.logic.browser.test.ts b/apps/web/src/components/ChatView.logic.browser.test.ts index 724c77538d315..46f67c156f203 100644 --- a/apps/web/src/components/ChatView.logic.browser.test.ts +++ b/apps/web/src/components/ChatView.logic.browser.test.ts @@ -65,6 +65,18 @@ it("keeps focus in a region with its own keys on window return", async () => { ); }); +it("keeps focus on a trigger whose menu just opened on window return", () => { + const trigger = document.createElement("button"); + trigger.setAttribute("aria-expanded", "true"); + document.body.append(trigger); + using _trigger = { [Symbol.dispose]: () => trigger.remove() }; + + trigger.focus(); + expect(shouldRefocusComposerOnWindowFocus(document.activeElement, null)).toBe(false); + trigger.setAttribute("aria-expanded", "false"); + expect(shouldRefocusComposerOnWindowFocus(document.activeElement, null)).toBe(true); +}); + it("refocuses the composer on window return from a clicked area after a bare key press", async () => { const controller = createWorkspaceFocusController(document); const root = document.createElement("div"); diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts index 1f8bb8e10043c..e408ff56614f7 100644 --- a/apps/web/src/components/ChatView.logic.ts +++ b/apps/web/src/components/ChatView.logic.ts @@ -1165,7 +1165,7 @@ export function shouldRefocusComposerOnWindowFocus( } return ( activeElement.closest( - '[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts]', + '[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts], [aria-expanded="true"]', ) === null ); } From d60dcc283072c6f858ed86a067efb8b9d50b7ab6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 15:31:47 +0000 Subject: [PATCH 5/5] fix(web): keep the composer refocus guard to open popup triggers `[aria-expanded="true"]` also matched expanded disclosure toggles (sidebar project folders, timeline folds, the diff collapse toggle), so focus stayed on them after returning to the window instead of going back to the composer. Require `aria-haspopup` too, which menu, popover, select and combobox triggers set. Co-Authored-By: Claude Opus 5.5 --- .../components/ChatView.logic.browser.test.ts | 17 +++++++++++++++-- apps/web/src/components/ChatView.logic.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/ChatView.logic.browser.test.ts b/apps/web/src/components/ChatView.logic.browser.test.ts index 46f67c156f203..fc285baf2a0f5 100644 --- a/apps/web/src/components/ChatView.logic.browser.test.ts +++ b/apps/web/src/components/ChatView.logic.browser.test.ts @@ -67,14 +67,27 @@ it("keeps focus in a region with its own keys on window return", async () => { it("keeps focus on a trigger whose menu just opened on window return", () => { const trigger = document.createElement("button"); + trigger.setAttribute("aria-haspopup", "menu"); trigger.setAttribute("aria-expanded", "true"); - document.body.append(trigger); - using _trigger = { [Symbol.dispose]: () => trigger.remove() }; + const disclosure = document.createElement("button"); + disclosure.setAttribute("aria-expanded", "true"); + document.body.append(trigger, disclosure); + using _buttons = { + [Symbol.dispose]: () => { + trigger.remove(); + disclosure.remove(); + }, + }; trigger.focus(); expect(shouldRefocusComposerOnWindowFocus(document.activeElement, null)).toBe(false); trigger.setAttribute("aria-expanded", "false"); expect(shouldRefocusComposerOnWindowFocus(document.activeElement, null)).toBe(true); + disclosure.focus(); + expect( + shouldRefocusComposerOnWindowFocus(document.activeElement, null), + "an expanded fold or folder toggle opens no popup", + ).toBe(true); }); it("refocuses the composer on window return from a clicked area after a bare key press", async () => { diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts index e408ff56614f7..50e25b828bb85 100644 --- a/apps/web/src/components/ChatView.logic.ts +++ b/apps/web/src/components/ChatView.logic.ts @@ -1165,7 +1165,7 @@ export function shouldRefocusComposerOnWindowFocus( } return ( activeElement.closest( - '[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts], [aria-expanded="true"]', + '[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts], [aria-haspopup][aria-expanded="true"]', ) === null ); }