Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/web/src/lib/openPullRequestLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
openPullRequestLink,
parseChangeRequestUrl,
PullRequestLinkOpenError,
shouldOpenPullRequestExternally,
} from "./openPullRequestLink";

describe("openPullRequestLink", () => {
Expand Down Expand Up @@ -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({
Expand Down
12 changes: 11 additions & 1 deletion apps/web/src/lib/openPullRequestLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey">,
): boolean {
return event.metaKey || event.ctrlKey;
}

export function useOpenChangeRequestLink(
threadRef?: ScopedThreadRef,
): (
event: Pick<MouseEvent<HTMLElement>, "preventDefault" | "stopPropagation">,
event: Pick<
MouseEvent<HTMLElement>,
"preventDefault" | "stopPropagation" | "metaKey" | "ctrlKey"
>,
targetUrl: string,
targetThreadRef?: ScopedThreadRef,
) => boolean {
Expand All @@ -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 (
Expand Down
Loading