Skip to content

Commit a8a6b1d

Browse files
fix(web): open modified PR clicks in browser
Co-authored-by: maria <[email protected]>
1 parent 5a84614 commit a8a6b1d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎apps/web/src/lib/openPullRequestLink.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
openPullRequestLink,
66
parseChangeRequestUrl,
77
PullRequestLinkOpenError,
8+
shouldOpenPullRequestExternally,
89
} from "./openPullRequestLink";
910

1011
describe("openPullRequestLink", () => {
@@ -34,6 +35,17 @@ describe("openPullRequestLink", () => {
3435
});
3536
});
3637

38+
describe("shouldOpenPullRequestExternally", () => {
39+
it("uses the browser for command-click and control-click", () => {
40+
expect(shouldOpenPullRequestExternally({ metaKey: true, ctrlKey: false })).toBe(true);
41+
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: true })).toBe(true);
42+
});
43+
44+
it("keeps an unmodified click in the pull request view", () => {
45+
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: false })).toBe(false);
46+
});
47+
});
48+
3749
describe("parseChangeRequestUrl", () => {
3850
it("reads a GitHub pull request", () => {
3951
expect(parseChangeRequestUrl("https://github.com/T3Tools/T3Code/pull/123")).toEqual({

‎apps/web/src/lib/openPullRequestLink.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,19 @@ export function findProjectForChangeRequest(
173173
* should still be reading it afterwards. Any change request opens there, not only the thread's
174174
* own, since the panel is told which one to show.
175175
*/
176+
export function shouldOpenPullRequestExternally(
177+
event: Pick<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey">,
178+
): boolean {
179+
return event.metaKey || event.ctrlKey;
180+
}
181+
176182
export function useOpenChangeRequestLink(
177183
threadRef?: ScopedThreadRef,
178184
): (
179-
event: Pick<MouseEvent<HTMLElement>, "preventDefault" | "stopPropagation">,
185+
event: Pick<
186+
MouseEvent<HTMLElement>,
187+
"preventDefault" | "stopPropagation" | "metaKey" | "ctrlKey"
188+
>,
180189
targetUrl: string,
181190
targetThreadRef?: ScopedThreadRef,
182191
) => boolean {
@@ -186,6 +195,7 @@ export function useOpenChangeRequestLink(
186195
const primaryEnvironmentId = usePrimaryEnvironmentId();
187196
return useCallback(
188197
(event, targetUrl, targetThreadRef) => {
198+
if (shouldOpenPullRequestExternally(event)) return false;
189199
const resolvedThreadRef = targetThreadRef ?? threadRef;
190200
const environmentId = resolvedThreadRef?.environmentId ?? primaryEnvironmentId;
191201
if (

0 commit comments

Comments
 (0)