diff --git a/apps/web/src/lib/openPullRequestLink.test.ts b/apps/web/src/lib/openPullRequestLink.test.ts index a08b992bb00..9d26fa29212 100644 --- a/apps/web/src/lib/openPullRequestLink.test.ts +++ b/apps/web/src/lib/openPullRequestLink.test.ts @@ -5,6 +5,7 @@ import { openPullRequestLink, parseChangeRequestUrl, PullRequestLinkOpenError, + shouldOpenPullRequestExternally, } from "./openPullRequestLink"; describe("openPullRequestLink", () => { @@ -34,6 +35,17 @@ describe("openPullRequestLink", () => { }); }); +describe("shouldOpenPullRequestExternally", () => { + it("uses the browser for command-click and control-click", () => { + expect(shouldOpenPullRequestExternally({ metaKey: true, ctrlKey: false })).toBe(true); + expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: true })).toBe(true); + }); + + it("keeps an unmodified click in the pull request view", () => { + expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: false })).toBe(false); + }); +}); + describe("parseChangeRequestUrl", () => { it("reads a GitHub pull request", () => { expect(parseChangeRequestUrl("https://github.com/T3Tools/T3Code/pull/123")).toEqual({ diff --git a/apps/web/src/lib/openPullRequestLink.ts b/apps/web/src/lib/openPullRequestLink.ts index 951c02e4b4d..8943f907b3f 100644 --- a/apps/web/src/lib/openPullRequestLink.ts +++ b/apps/web/src/lib/openPullRequestLink.ts @@ -173,10 +173,19 @@ export function findProjectForChangeRequest( * should still be reading it afterwards. Any change request opens there, not only the thread's * own, since the panel is told which one to show. */ +export function shouldOpenPullRequestExternally( + event: Pick, "metaKey" | "ctrlKey">, +): boolean { + return event.metaKey || event.ctrlKey; +} + export function useOpenChangeRequestLink( threadRef?: ScopedThreadRef, ): ( - event: Pick, "preventDefault" | "stopPropagation">, + event: Pick< + MouseEvent, + "preventDefault" | "stopPropagation" | "metaKey" | "ctrlKey" + >, targetUrl: string, targetThreadRef?: ScopedThreadRef, ) => boolean { @@ -186,6 +195,7 @@ export function useOpenChangeRequestLink( const primaryEnvironmentId = usePrimaryEnvironmentId(); return useCallback( (event, targetUrl, targetThreadRef) => { + if (shouldOpenPullRequestExternally(event)) return false; const resolvedThreadRef = targetThreadRef ?? threadRef; const environmentId = resolvedThreadRef?.environmentId ?? primaryEnvironmentId; if (