diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx new file mode 100644 index 0000000000000..1e4de32289e69 --- /dev/null +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx @@ -0,0 +1,59 @@ +import { createRef, type RefObject } from "react"; +import { describe, expect, it } from "vite-plus/test"; + +import { render } from "../../../test/render"; +import { PullRequestsColumn } from "./PullRequestsColumn"; + +function createColumn(maximizedAway: boolean, scrollRef: RefObject) { + return ( + {}} + searchValue="" + involvement="all" + state="open" + host={undefined} + hostMenuOptions={[]} + onInvolvement={() => {}} + onState={() => {}} + onHost={() => {}} + searchInput={} + sortMenu={null} + filtersMenu={null} + savedViewsMenu={null} + rightPanelControl={null} + titlebarControls={null} + rightPanelOpen={maximizedAway} + maximizedAway={maximizedAway} + listBody={null} + scrollRef={scrollRef} + /> + ); +} + +function dispatchFindShortcut() { + const event = new KeyboardEvent("keydown", { + key: "f", + ctrlKey: true, + bubbles: true, + cancelable: true, + }); + window.dispatchEvent(event); + return event; +} + +describe("PullRequestsColumn find shortcut", () => { + it("leaves Cmd/Ctrl+F to the browser while the detail panel is maximized", async () => { + const scrollRef = createRef(); + await using screen = await render(createColumn(false, scrollRef)); + + await screen.rerender(createColumn(true, scrollRef)); + expect(dispatchFindShortcut().defaultPrevented).toBe(false); + + await screen.rerender(createColumn(false, scrollRef)); + expect(dispatchFindShortcut().defaultPrevented).toBe(true); + await expect + .element(screen.getByRole("textbox", { name: "Search pull requests" })) + .toHaveFocus(); + }); +}); diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.tsx index fdfe825790ba6..d4ca6d0d3b7e2 100644 --- a/apps/web/src/components/pullRequest/PullRequestsColumn.tsx +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.tsx @@ -138,6 +138,7 @@ export function PullRequestsColumn({ const searchExpanded = searchOpen || searchValue.length > 0; // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window keydown listener focuses the visible search input on Cmd/Ctrl+F useEffect(() => { + if (maximizedAway) return; const onKeyDown = (event: KeyboardEvent) => { if (event.defaultPrevented) return; if (event.key.toLowerCase() !== "f" || !(event.metaKey || event.ctrlKey)) return; @@ -151,7 +152,7 @@ export function PullRequestsColumn({ }; window.addEventListener("keydown", onKeyDown); return () => window.removeEventListener("keydown", onKeyDown); - }, [condensed]); + }, [condensed, maximizedAway]); if (!condensed && searchOpen) setSearchOpen(false); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- moves DOM focus to the in-flow search when the topbar search it was typed in unmounts useEffect(() => { diff --git a/apps/web/src/shortcuts/chatRouteCommands.test.ts b/apps/web/src/shortcuts/chatRouteCommands.test.ts index 3979368ff9032..db332610cd923 100644 --- a/apps/web/src/shortcuts/chatRouteCommands.test.ts +++ b/apps/web/src/shortcuts/chatRouteCommands.test.ts @@ -105,4 +105,21 @@ describe("preview commands", () => { expect(dispatch).toHaveBeenCalledWith(action); }); + + it("preview.find leaves the key unclaimed on non-thread chat routes", () => { + using dispatch = vi.spyOn(previewActions, "dispatchPreviewAction").mockImplementation(() => {}); + using register = vi.spyOn(dispatcher, "registerCommands").mockReturnValue(() => {}); + const router = { + state: { matches: [{ routeId: "/_chat/pull-requests", params: {} }] }, + } as unknown as AnyRouter; + using stack = new DisposableStack(); + stack.defer(installChatRouteCommands(router)); + const event = { preventDefault: vi.fn(), stopPropagation: vi.fn() } as unknown as KeyboardEvent; + + const result = register.mock.calls[0]![0]["preview.find"]!(event); + + expect(result).toBe(false); + expect(event.preventDefault).not.toHaveBeenCalled(); + expect(dispatch).not.toHaveBeenCalled(); + }); }); diff --git a/apps/web/src/shortcuts/chatRouteCommands.ts b/apps/web/src/shortcuts/chatRouteCommands.ts index 7cca45fbd81db..90ccf9fc2023f 100644 --- a/apps/web/src/shortcuts/chatRouteCommands.ts +++ b/apps/web/src/shortcuts/chatRouteCommands.ts @@ -186,7 +186,13 @@ export function installChatRouteCommands(router: AnyRouter): () => void { "preview.zoomIn": zoomCommand("zoom-in"), "preview.zoomOut": zoomCommand("zoom-out"), "preview.resetZoom": zoomCommand("reset-zoom"), - "preview.find": previewCommand("find"), + // Unclaimed, the browser's own find runs when no thread handles panel find. + "preview.find": (event) => { + const environmentId = readRouteEnvironmentId(); + if (!environmentId || !canOperatePreview(environmentId)) return false; + claim(event); + dispatchPreviewAction("find"); + }, }, { when: () =>