@devries-cameron20 / t3code Mirror · read-only / commits / 9cb59bf858
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 09:30 UTC

fix(web): mod+L focuses the browser address bar from a focused page (#22328)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

John Nunemaker committed Oct 31, 2026 at 22:21 UTC 9cb59bf8587daebfa762e35b9d7ca3bc947d0e56
6 files changed +82 -6
apps/desktop/src/preview/Manager.test.ts
+19 -2
@@ -619,7 +619,8 @@ describe("PreviewManager", () => {
619 withManager((manager) =>
620 Effect.gen(function* () {
621 const send = vi.fn();
622 - const host = { isDestroyed: () => false, send };
622 + const focus = vi.fn();
623 + const host = { isDestroyed: () => false, send, focus };
624 const older = makeFaviconWebContents({ id: 42 });
625 const newer = makeFaviconWebContents({ id: 43 });
626 for (const tab of [older, newer]) Object.assign(tab.webContents, { hostWebContents: host });
@@ -648,6 +649,22 @@ describe("PreviewManager", () => {
649 expect(preventDefault).toHaveBeenCalledOnce();
650 expect(send).toHaveBeenCalledExactlyOnceWith("desktop:menu-action", "view.reopenClosed");
651
652 + yield* manager.setForwardedShortcuts([
653 + { command: "preview.focusUrl", shortcut: parseKeybindingShortcut("mod+l")! },
654 + ]);
655 + beforeInput({ preventDefault } as never, { ...key, key: "l", shift: false } as never);
656 + expect(focus).toHaveBeenCalledOnce();
657 + expect(send).toHaveBeenLastCalledWith("desktop:menu-action", "preview.focusUrl");
658 + expect(focus.mock.invocationCallOrder[0]).toBeLessThan(send.mock.invocationCallOrder[1]!);
659 + beforeInput(
660 + { preventDefault } as never,
661 + { ...key, key: "l", shift: false, isAutoRepeat: true } as never,
662 + );
663 + expect(focus).toHaveBeenCalledOnce();
664 + expect(send).toHaveBeenCalledTimes(2);
665 + send.mockClear();
666 + yield* manager.setForwardedShortcuts([{ command: "view.reopenClosed", shortcut }]);
667 +
668 Object.assign(newer.webContents, { focusedFrame: null });
669 const agentInput = newer.listeners.get("before-input-event")!;
670 const agentPreventDefault = vi.fn();
@@ -663,7 +680,7 @@ describe("PreviewManager", () => {
680 { ...key, key: "T", shift: true } as never,
681 );
682 expect(agentPreventDefault).not.toHaveBeenCalled();
666 - expect(send).toHaveBeenCalledOnce();
683 + expect(send).not.toHaveBeenCalled();
684 }),
685 ),
686 );
apps/desktop/src/preview/Manager.ts
+2 -1
@@ -1478,7 +1478,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
1478 if (!input.isAutoRepeat) {
1479 if (
1480 forwarded.command === "workspace.focusNext" ||
1481 - forwarded.command === "workspace.focusPrevious"
1481 + forwarded.command === "workspace.focusPrevious" ||
1482 + forwarded.command === "preview.focusUrl"
1483 ) {
1484 // DOM focus in the renderer cannot by itself release the guest's native keyboard focus.
1485 host.focus();
apps/web/src/components/ReopenClosedViewShortcut.browser.test.tsx
+7
@@ -265,4 +265,11 @@ describe("root reopen shortcut", () => {
265 expect(useClosedViewStore.getState().entries).toEqual([]);
266 },
267 );
268 + it("forwards address-bar focus from a focused desktop page", async () => {
269 + setup();
270 + await using _shortcut = await renderShortcut();
271 + expect(state.setShortcuts).toHaveBeenLastCalledWith(
272 + expect.arrayContaining([expect.objectContaining({ command: "preview.focusUrl" })]),
273 + );
274 + });
275 });
apps/web/src/components/ReopenClosedViewShortcut.tsx
+3 -2
@@ -43,12 +43,13 @@ import {
43 } from "../threadRoutes";
44 import { toastManager } from "./ui/toast";
45
46 -const PREVIEW_FORWARDED_LAYOUT_COMMANDS = [
46 +const PREVIEW_FORWARDED_COMMANDS = [
47 "workspace.focusNext",
48 "workspace.focusPrevious",
49 "sidebar.toggle",
50 "rightPanel.toggle",
51 "rightPanel.toggleMaximized",
52 + "preview.focusUrl",
53 ] as const;
54
55 const isGlobalPullRequests = (ref: ScopedThreadRef) =>
@@ -205,7 +206,7 @@ export function ReopenClosedViewShortcut() {
206 // Guest browser processes miss app keydown listeners; desktop forwards the chords as menu actions.
207 const commands = [
208 ...(hasHistory ? (["view.reopenClosed"] as const) : []),
208 - ...PREVIEW_FORWARDED_LAYOUT_COMMANDS,
209 + ...PREVIEW_FORWARDED_COMMANDS,
210 ];
211 void preview
212 .setForwardedShortcuts(
apps/web/src/components/preview/PreviewView.browser.test.tsx
+43
@@ -286,6 +286,49 @@ describe("PreviewView", () => {
286 expect(mocks.addImage).not.toHaveBeenCalled();
287 });
288
289 + it("focuses and selects the address from forwarded desktop actions only while visible", async () => {
290 + setup();
291 + using stack = new DisposableStack();
292 + const previousBridge = window.desktopBridge;
293 + stack.defer(() => {
294 + if (previousBridge) window.desktopBridge = previousBridge;
295 + else delete window.desktopBridge;
296 + });
297 + const listeners = new Set<(action: string) => void>();
298 + window.desktopBridge = {
299 + getWindowZoomFactor: () => 1,
300 + onMenuAction: (listener: (action: string) => void) => {
301 + listeners.add(listener);
302 + return () => {
303 + listeners.delete(listener);
304 + };
305 + },
306 + } as NonNullable<typeof window.desktopBridge>;
307 + await using screen = await render(view());
308 + const address = page.getByRole("textbox");
309 + const input = address.element() as HTMLInputElement;
310 + const forward = () =>
311 + act(() => {
312 + listeners.forEach((listener) => listener("preview.focusUrl"));
313 + });
314 +
315 + await forward();
316 + await expect.element(address).toHaveFocus();
317 + expect(input.selectionStart).toBe(0);
318 + expect(input.selectionEnd).toBe(input.value.length);
319 + await act(() => input.blur());
320 + await forward();
321 + await expect.element(address).toHaveFocus();
322 +
323 + await act(() => input.blur());
324 + await screen.rerender(
325 + <PreviewView threadRef={TEST_THREAD_REF} tabId="tab-1" visible={false} />,
326 + );
327 + await forward();
328 + await expect.element(address).not.toHaveFocus();
329 + expect(listeners.size).toBe(0);
330 + });
331 +
332 it("focuses the address bar each time the focus-url shortcut fires", async () => {
333 setup();
334 await using _screen = await render(view());
apps/web/src/components/preview/PreviewView.tsx
+8 -1
@@ -860,7 +860,14 @@ export function PreviewView({
860 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to preview actions while the view is visible
861 useEffect(() => {
862 if (!visible) return;
863 - return subscribePreviewAction((action) => onPreviewAction(action));
863 + const unsubscribeAction = subscribePreviewAction((action) => onPreviewAction(action));
864 + const unsubscribeMenu = window.desktopBridge?.onMenuAction((action) => {
865 + if (action === "preview.focusUrl") onPreviewAction("focus-url");
866 + });
867 + return () => {
868 + unsubscribeAction();
869 + unsubscribeMenu?.();
870 + };
871 }, [visible]);
872
873 return (