Skip to content

Commit 00cdceb

Browse files
t3dotggclaude
andauthored
fix(web): middle-click opens pull requests in the browser, like cmd+click (#19854)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent cd34df5 commit 00cdceb

8 files changed

Lines changed: 43 additions & 7 deletions

File tree

‎apps/web/src/browser/browserLinkTarget.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ describe("resolveLinkTarget", () => {
6767
canOpenInApp: true,
6868
}),
6969
).toBe("system");
70+
expect(
71+
resolveLinkTarget({
72+
url: "https://example.com/",
73+
event: { metaKey: false, ctrlKey: false, button: 1 },
74+
preference: "app",
75+
canOpenInApp: true,
76+
}),
77+
).toBe("system");
7078
});
7179

7280
it("leaves non-web schemes to the shell", () => {

‎apps/web/src/browser/browserLinkTarget.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ import { isPreviewAvailableFor } from "./previewRuntime";
1515

1616
export interface ResolveLinkTargetInput {
1717
readonly url: string;
18-
/** Cmd/Ctrl-click always goes to the system browser, whatever the default. */
19-
readonly event: { readonly metaKey: boolean; readonly ctrlKey: boolean };
18+
/** Cmd/Ctrl-click and middle-click always go to the system browser, whatever the default. */
19+
readonly event: {
20+
readonly metaKey: boolean;
21+
readonly ctrlKey: boolean;
22+
readonly button?: number | undefined;
23+
};
2024
readonly preference: BrowserLinkTarget;
2125
/** Whether this client has an in-app browser and a thread to open it beside. */
2226
readonly canOpenInApp: boolean;
@@ -30,7 +34,7 @@ export interface ResolveLinkTargetInput {
3034
* already treat it.
3135
*/
3236
export function resolveLinkTarget(input: ResolveLinkTargetInput): BrowserLinkTarget {
33-
if (input.event.metaKey || input.event.ctrlKey) return "system";
37+
if (input.event.metaKey || input.event.ctrlKey || input.event.button === 1) return "system";
3438
if (input.preference !== "app") return "system";
3539
if (!input.canOpenInApp) return "system";
3640
if (!isWebUrl(input.url)) return "system";

‎apps/web/src/browser/useOpenLink.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ const NO_MODIFIER = { metaKey: false, ctrlKey: false } as const;
3434
export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): (
3535
url: string,
3636
options?: {
37-
readonly event?: { readonly metaKey: boolean; readonly ctrlKey: boolean };
37+
readonly event?: {
38+
readonly metaKey: boolean;
39+
readonly ctrlKey: boolean;
40+
readonly button?: number | undefined;
41+
};
3842
/** Thread to open beside when it is not the hook's own, e.g. a sidebar row's. */
3943
readonly threadRef?: ScopedThreadRef | undefined;
4044
},

‎apps/web/src/components/chat/ThreadDetailsPrRow.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export function ThreadDetailsPrRow({
395395
part={part}
396396
aria-label={openAriaLabel}
397397
onClick={onOpen}
398+
onAuxClick={onOpen}
398399
/>
399400
}
400401
>

‎apps/web/src/components/contextChipParts.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export function PullRequestChip(props: {
113113
aria-label={`Open ${props.kindLabel} ${props.label}: ${props.metadata.title}`}
114114
data-markdown-copy={props.copyMarkdown}
115115
onClick={(event) => props.onOpen(event, props.metadata.url)}
116+
onAuxClick={(event) => props.onOpen(event, props.metadata.url)}
116117
>
117118
<StateIcon />
118119
<ContextChipLabel>{props.label}</ContextChipLabel>

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,10 @@ export function PullRequestDetailPanel({
18761876
<button
18771877
type="button"
18781878
onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}
1879+
onAuxClick={(event) => {
1880+
if (event.button === 1)
1881+
void readLocalApi()?.shell.openExternal(detail.url);
1882+
}}
18791883
onContextMenu={(event) => openNumberContextMenu(event, detail)}
18801884
className={cn(
18811885
"inline-flex shrink-0 cursor-pointer items-center gap-0.5 font-medium underline-offset-2 hover:underline",
@@ -1931,6 +1935,10 @@ export function PullRequestDetailPanel({
19311935
type="button"
19321936
tabIndex={condensed ? 0 : -1}
19331937
onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}
1938+
onAuxClick={(event) => {
1939+
if (event.button === 1)
1940+
void readLocalApi()?.shell.openExternal(detail.url);
1941+
}}
19341942
onContextMenu={(event) => openNumberContextMenu(event, detail)}
19351943
className={cn(
19361944
"inline-flex shrink-0 cursor-pointer items-center gap-0.5 font-medium underline-offset-2 hover:underline",

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ describe("shouldOpenPullRequestExternally", () => {
221221
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: true })).toBe(true);
222222
});
223223

224+
it("uses the browser for middle-click", () => {
225+
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: false, button: 1 })).toBe(
226+
true,
227+
);
228+
});
229+
224230
it("keeps an unmodified click in the pull request view", () => {
225231
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: false })).toBe(false);
226232
});

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ export function findProjectOnChangeRequestHost(
126126
*
127127
* With "Open pull requests in T3 Code" turned off, every link is left alone.
128128
*/
129+
/** Cmd/Ctrl-click and middle-click send a pull request to the browser instead of the panel. */
129130
export function shouldOpenPullRequestExternally(
130-
event: Pick<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey">,
131+
event: Pick<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey"> &
132+
Partial<Pick<MouseEvent<HTMLElement>, "button">>,
131133
): boolean {
132-
return event.metaKey || event.ctrlKey;
134+
return event.metaKey || event.ctrlKey || event.button === 1;
133135
}
134136

135137
export function useOpenChangeRequestLink(
@@ -256,11 +258,13 @@ export function useOpenPrLink(threadRef?: ScopedThreadRef) {
256258
const openLink = useOpenLink(threadRef);
257259
return useCallback(
258260
(event: MouseEvent<HTMLElement>, prUrl: string, targetThreadRef?: ScopedThreadRef) => {
261+
// Buttons also pass this to onAuxClick for middle-click; a right-click is not an open.
262+
if (event.button > 1) return false;
259263
event.stopPropagation();
260264
const openInBrowser = shouldOpenPullRequestExternally(event);
261265
const isAnchor =
262266
event.currentTarget instanceof HTMLAnchorElement && event.currentTarget.href.length > 0;
263-
// A real link already knows how to cmd/ctrl+click. Leave its default
267+
// A real link already knows how to cmd/ctrl/middle-click. Leave its default
264268
// action alone so the browser (or Electron's window-open handler) opens
265269
// the host. Buttons have no href, so they still go through openExternal.
266270
if (openInBrowser && isAnchor) return false;

0 commit comments

Comments
 (0)