From c74fb3c71b980e1734a22e0a5d3109138bb00be9 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Wed, 29 Jul 2026 12:30:48 -0700 Subject: [PATCH] feat(browser): let Shift invert link routing instead of always forcing the system browser (#10991) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(browser): let Shift invert link routing instead of always forcing the system browser Shift+Cmd/Ctrl-click has always meant "open in the system browser", which is a no-op when that is already where links go. Users who keep Link Routing off have had no gesture to pull a single link into Orca's built-in browser. Adds "Hold Shift to open in ___", a nested toggle under Link Routing that makes the modifier open a link the opposite way from the setting. It ships off, so the one-way escape hatch is unchanged for every existing user. The title and description name the destination the modifier actually reaches and flip with the parent setting, since "the opposite" is meaningless on its own. - openHttpLink gains modifierHeld; resolveModifierRouting owns the decision so every surface (terminal URLs, OSC 8, xterm web links, markdown preview) routes identically. forceSystemBrowser stays for callers that must bypass settings. - The terminal hover hint names Orca when the modifier would open there, and is re-resolved per hover so toggling applies without recreating panes. - Link Routing's own copy drops "always uses your system browser", which the new toggle can falsify; the nested row states the live destination instead. * fix(browser): route the Checks panel hosted-review link through the shared modifier The "Open on GitHub" button had its own Shift+Cmd/Ctrl escape hatch that passed forceSystemBrowser directly, so it kept the old one-way behavior while every other surface honored the invert setting. Route it through modifierHeld like the terminal and markdown paths. Also wraps the modifier row's description in translate(); the title in the same file was localized but the description returned raw English (caught in review). * fix(browser): make link-routing modifier copy true in every state Review follow-ups on the Shift-inverts-routing change. - The nested row promised "⇧⌘+click opens one in Orca" in the present tense while its own toggle was off, so the out-of-box state described behavior the user did not have. Phrase it as enabled-state copy, matching sibling rows. - The parent Link Routing description gained "opens a link the other way", which is false in the default state and contradicts the child row when inverting is on. No fixed sentence there is true in every state, so the child row — which knows the live destination — now owns the claim. That leaves getBrowserLinkRoutingShortcutLabel unused, so drop it. - The rich markdown editor still forced the system browser while the preview of the same file honored the modifier, so one link routed two ways depending on which view it was clicked in. - A remote runtime pins every link to the system browser, so the hover hint could promise Orca for a click that lands elsewhere. Gate the hint on the same condition openHttpLink uses. - Index both modifier titles: the search entry is built with openLinksInApp false, so the row was unfindable by the title it renders when routing is on. - Drop the ariaLabel that shared no words with the visible label (WCAG 2.5.3) and add the four missing settings-search keyword keys to all five catalogs. * test(editor): pin the rich markdown Shift+click routing hop The editor half of the modifier fix had no coverage — reverting it to forceSystemBrowser left the suite green while the same link routed one way in the markdown preview and the other way in the rich editor. Also pins that a non-local source owner survives the hop, since that is what keeps an SSH file's links out of Orca's browser. * test(editor): cover the Ctrl chord for rich markdown link routing This file is the only test of handleRichMarkdownEditorClick, and it exercised metaKey alone, so the isMac branch of modKey had no coverage off macOS. Also stop claiming the source-owner case proves SSH links stay out of Orca — it proves the owner survives the hop; http-link-routing.test.ts enforces the rest. * style: trim review comments to the one-line house rule Both explained the change adequately in two lines; the extra lines were worked examples, not information. * fix(browser): keep Link Routing copy unchanged until inverting is enabled Removing the "⇧⌘-click always uses your system browser" sentence outright reworded the row for every user on upgrade, including everyone who never turns the opt-in on. Restore it verbatim in the default state and only hand the chord sentence to the nested row once inverting makes "always" untrue. * revert(editor): keep rich markdown Shift+click on the system browser Per Brennan: the editor's Shift path hands the link to the client OS and should not follow the invert setting — the preview opening in Orca is the intended divergence, not a bug. Restores main's call exactly; the test now pins the divergence so a future consistency pass cannot erase it silently. * fix(browser): surface the inverted modifier on the hosted-review link The hosted-review click path now passes modifierHeld, so with inverting on and Link Routing off the chord opens in Orca — but the hint stayed gated on openLinksInApp, hiding a live gesture. Resolve the destination instead of a boolean. Default-off output is unchanged. * test(browser): pin the inert modifier hint when links already open in Orca * refactor(terminal): require the pane link hint so dropping the wiring fails to build The optional option fell back to a duplicated copy of the legacy hint string, so deleting the hook wiring reverted the tooltip silently with every test green. * fix(browser): trim the runtime id before hiding the hosted-review modifier hint openHttpLink and terminalUrlOpenHintOptionsFor both trim, so a blank runtime id hid the hint while the click still reached Orca. --- .../editor/markdown-preview-links.test.ts | 14 +-- .../editor/markdown-preview-links.ts | 10 +- ...rich-markdown-editor-click-routing.test.ts | 84 ++++++++++++++ .../rich-markdown-editor-click-routing.ts | 2 + .../ChecksPanel.review-header.test.tsx | 22 +++- .../components/right-sidebar/ChecksPanel.tsx | 32 ++++-- ...-panel-hosted-review-click-routing.test.ts | 106 ++++++++++++++++-- ...hecks-panel-hosted-review-click-routing.ts | 31 ++++- .../BrowserLinkRoutingModifierSetting.tsx | 54 +++++++++ .../src/components/settings/BrowserPane.tsx | 21 +++- .../browser-link-routing-modifier-copy.ts | 42 +++++++ .../settings/browser-search.test.ts | 101 +++++++++++++---- .../src/components/settings/browser-search.ts | 53 ++++++++- .../edge-wrapped-terminal-http-links.test.ts | 44 ++++---- .../repro-8832-url-next-line.test.ts | 2 +- .../terminal-link-open-hints.test.ts | 89 +++++++++++++++ .../terminal-pane/terminal-link-open-hints.ts | 41 ++++++- .../terminal-osc-link-routing.ts | 2 +- .../terminal-url-link-hit-testing.ts | 10 +- .../terminal-pane/terminal-web-link-click.ts | 2 +- .../use-terminal-pane-lifecycle.ts | 7 +- src/renderer/src/i18n/locales/en.json | 12 ++ src/renderer/src/i18n/locales/es.json | 12 ++ src/renderer/src/i18n/locales/ja.json | 12 ++ src/renderer/src/i18n/locales/ko.json | 12 ++ src/renderer/src/i18n/locales/zh.json | 12 ++ .../lib/http-link-modifier-routing.test.ts | 51 +++++++++ .../src/lib/http-link-routing.test.ts | 76 +++++++++++++ src/renderer/src/lib/http-link-routing.ts | 44 +++++++- .../pane-manager/pane-dom-creation.test.ts | 46 +++----- .../src/lib/pane-manager/pane-dom-creation.ts | 8 +- .../lib/pane-manager/pane-manager-types.ts | 4 + .../lib/pane-manager/pane-split-close.test.ts | 2 +- .../pane-terminal-gpu-acceleration.test.ts | 25 ++++- src/shared/constants.ts | 1 + src/shared/telemetry-events.ts | 1 + src/shared/types.ts | 2 + 37 files changed, 940 insertions(+), 149 deletions(-) create mode 100644 src/renderer/src/components/editor/rich-markdown-editor-click-routing.test.ts create mode 100644 src/renderer/src/components/settings/BrowserLinkRoutingModifierSetting.tsx create mode 100644 src/renderer/src/components/settings/browser-link-routing-modifier-copy.ts create mode 100644 src/renderer/src/components/terminal-pane/terminal-link-open-hints.test.ts create mode 100644 src/renderer/src/lib/http-link-modifier-routing.test.ts diff --git a/src/renderer/src/components/editor/markdown-preview-links.test.ts b/src/renderer/src/components/editor/markdown-preview-links.test.ts index 439541add..530e05c2b 100644 --- a/src/renderer/src/components/editor/markdown-preview-links.test.ts +++ b/src/renderer/src/components/editor/markdown-preview-links.test.ts @@ -141,10 +141,10 @@ describe('isMarkdownPreviewSystemBrowserModifier', () => { }) describe('resolveMarkdownPreviewHttpOpenOptions', () => { - // forceSystemBrowser -> shell.openExternal (system default browser); - // worktreeId (no force) -> openHttpLink routes into the Orca browser per the - // openLinksInApp setting. See http-link-routing.test.ts for that mapping. - it('forces the system browser on Cmd+Shift-click on macOS', () => { + // modifierHeld -> openHttpLink resolves the escape hatch against the + // openLinksInApp / openLinksInAppModifierInverts pair; worktreeId (no + // modifier) routes per the setting. See http-link-routing.test.ts. + it('marks the modifier held on Cmd+Shift-click on macOS', () => { expect( resolveMarkdownPreviewHttpOpenOptions( { metaKey: true, ctrlKey: false, shiftKey: true }, @@ -152,10 +152,10 @@ describe('resolveMarkdownPreviewHttpOpenOptions', () => { 'wt-1', { kind: 'local' } ) - ).toEqual({ forceSystemBrowser: true, sourceOwner: { kind: 'local' } }) + ).toEqual({ worktreeId: 'wt-1', modifierHeld: true, sourceOwner: { kind: 'local' } }) }) - it('forces the system browser on Ctrl+Shift-click on Linux/Windows', () => { + it('marks the modifier held on Ctrl+Shift-click on Linux/Windows', () => { expect( resolveMarkdownPreviewHttpOpenOptions( { metaKey: false, ctrlKey: true, shiftKey: true }, @@ -163,7 +163,7 @@ describe('resolveMarkdownPreviewHttpOpenOptions', () => { 'wt-1', { kind: 'local' } ) - ).toEqual({ forceSystemBrowser: true, sourceOwner: { kind: 'local' } }) + ).toEqual({ worktreeId: 'wt-1', modifierHeld: true, sourceOwner: { kind: 'local' } }) }) it('routes a plain Cmd-click through the worktree so it can open in Orca', () => { diff --git a/src/renderer/src/components/editor/markdown-preview-links.ts b/src/renderer/src/components/editor/markdown-preview-links.ts index 0541ca0ab..6062180ac 100644 --- a/src/renderer/src/components/editor/markdown-preview-links.ts +++ b/src/renderer/src/components/editor/markdown-preview-links.ts @@ -113,10 +113,10 @@ export function isMarkdownPreviewSystemBrowserModifier( return event.shiftKey && (isMac ? event.metaKey : event.ctrlKey) } -// Why: Cmd/Ctrl+Shift-click is the escape hatch that forces the OS default -// browser; every other click routes through openHttpLink so the "open links in -// Orca" setting (and remote-runtime state) decides the destination. Mac uses -// metaKey, Linux/Windows use ctrlKey per AGENTS.md. +// Why: Cmd/Ctrl+Shift-click is the escape hatch; every click routes through +// openHttpLink so the "open links in Orca" setting (and remote-runtime state) +// decides the destination, with modifierHeld telling it the escape hatch fired. +// Mac uses metaKey, Linux/Windows use ctrlKey per AGENTS.md. export function resolveMarkdownPreviewHttpOpenOptions( event: Pick, isMac: boolean, @@ -124,7 +124,7 @@ export function resolveMarkdownPreviewHttpOpenOptions( sourceOwner: HttpLinkSourceOwner ): OpenHttpLinkOptions { if (isMarkdownPreviewSystemBrowserModifier(event, isMac)) { - return { forceSystemBrowser: true, sourceOwner } + return { worktreeId, modifierHeld: true, sourceOwner } } return { worktreeId, sourceOwner } } diff --git a/src/renderer/src/components/editor/rich-markdown-editor-click-routing.test.ts b/src/renderer/src/components/editor/rich-markdown-editor-click-routing.test.ts new file mode 100644 index 000000000..c7ae685f8 --- /dev/null +++ b/src/renderer/src/components/editor/rich-markdown-editor-click-routing.test.ts @@ -0,0 +1,84 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import type { MutableRefObject } from 'react' +import type { EditorView } from '@tiptap/pm/view' +import { handleRichMarkdownEditorClick } from './rich-markdown-editor-click-routing' +import type { HttpLinkSourceOwner } from '@/lib/http-link-routing' + +const openHttpLinkMock = vi.hoisted(() => vi.fn()) + +vi.mock('@/lib/http-link-routing', () => ({ + openHttpLink: openHttpLinkMock +})) + +beforeEach(() => { + openHttpLinkMock.mockReset() +}) + +// Why: the preview deliberately routes differently; this pins the editor side so a +// future "make them consistent" change cannot land silently. +function clickExternalLinkWithShift(sourceOwner: HttpLinkSourceOwner, isMac = true): boolean { + const href = 'https://example.com/docs' + const view = { + state: { + doc: { + nodeAt: () => null, + resolve: () => ({ + marks: () => [{ type: { name: 'link' }, attrs: { href } }] + }) + } + } + } as unknown as EditorView + + return handleRichMarkdownEditorClick({ + activateMarkdownLink: vi.fn(), + editorRef: { current: {} } as unknown as MutableRefObject, + event: { metaKey: isMac, ctrlKey: !isMac, shiftKey: true } as MouseEvent, + filePath: '/repo/docs/README.md', + isMac, + htmlSuperscriptLinkContext: { + getSnapshot: () => ({ sourceOwner }) + }, + markdownCommentsRef: { current: [] }, + markdownSourceLineOffsetRef: { current: 0 }, + onOpenDocLinkRef: { current: undefined }, + pos: 1, + rootRef: { current: null }, + scrollRichMarkdownReviewNoteCardIntoView: vi.fn(), + settings: {} as never, + view, + worktreeId: 'wt-1', + worktreeRoot: '/repo' + } as never) +} + +describe('rich markdown editor Shift+modifier click on external links', () => { + // Why: intentionally NOT the preview's behavior — this path hands the link to the + // client OS, so it must keep forcing the system browser even when inverting is on. + it('forces the system browser rather than following the invert setting', () => { + expect(clickExternalLinkWithShift({ kind: 'local' })).toBe(true) + expect(openHttpLinkMock).toHaveBeenCalledWith('https://example.com/docs', { + forceSystemBrowser: true, + sourceOwner: { kind: 'local' } + }) + }) + + // Why: AGENTS.md — Shift+Ctrl is the chord off macOS, and modKey reads a + // different event field there. + it('uses the Ctrl chord off macOS', () => { + expect(clickExternalLinkWithShift({ kind: 'local' }, false)).toBe(true) + expect(openHttpLinkMock).toHaveBeenCalledWith('https://example.com/docs', { + forceSystemBrowser: true, + sourceOwner: { kind: 'local' } + }) + }) + + it('forwards a non-local source owner untouched', () => { + const sourceOwner = { kind: 'ssh', connectionId: 'conn-1' } as HttpLinkSourceOwner + + expect(clickExternalLinkWithShift(sourceOwner)).toBe(true) + expect(openHttpLinkMock).toHaveBeenCalledWith( + 'https://example.com/docs', + expect.objectContaining({ forceSystemBrowser: true, sourceOwner }) + ) + }) +}) diff --git a/src/renderer/src/components/editor/rich-markdown-editor-click-routing.ts b/src/renderer/src/components/editor/rich-markdown-editor-click-routing.ts index 4c0f0ca96..9078f0e76 100644 --- a/src/renderer/src/components/editor/rich-markdown-editor-click-routing.ts +++ b/src/renderer/src/components/editor/rich-markdown-editor-click-routing.ts @@ -204,6 +204,8 @@ function openMarkdownLinkInClientOs({ return } if (classified.kind === 'external') { + // Why: deliberate divergence from the preview — this path hands the link to the + // client OS unconditionally, so it does not follow the invert setting. openHttpLink(classified.url, { forceSystemBrowser: true, sourceOwner }) return } diff --git a/src/renderer/src/components/right-sidebar/ChecksPanel.review-header.test.tsx b/src/renderer/src/components/right-sidebar/ChecksPanel.review-header.test.tsx index 480943798..c9d535b2a 100644 --- a/src/renderer/src/components/right-sidebar/ChecksPanel.review-header.test.tsx +++ b/src/renderer/src/components/right-sidebar/ChecksPanel.review-header.test.tsx @@ -2,6 +2,7 @@ import type { ReactNode } from 'react' import { renderToStaticMarkup } from 'react-dom/server' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { ChecksPanelReviewHeader } from './ChecksPanel' +import type { ChecksPanelHostedReviewModifierDestination } from './checks-panel-hosted-review-click-routing' vi.mock('@/components/ui/dropdown-menu', () => ({ DropdownMenu: ({ children }: { children: ReactNode }) =>
{children}
, @@ -30,11 +31,11 @@ afterEach(() => { function renderHeader({ canUnlinkPullRequest = true, provider = 'github', - showSystemBrowserHint = true + modifierHintDestination = 'system-browser' }: { canUnlinkPullRequest?: boolean provider?: 'github' | 'gitlab' - showSystemBrowserHint?: boolean + modifierHintDestination?: ChecksPanelHostedReviewModifierDestination } = {}): string { const isGitLab = provider === 'gitlab' return renderToStaticMarkup( @@ -53,7 +54,7 @@ function renderHeader({ }} isRefreshing={false} canUnlinkPullRequest={canUnlinkPullRequest} - showSystemBrowserHint={showSystemBrowserHint} + modifierHintDestination={modifierHintDestination} onRefresh={vi.fn()} onOpenReview={vi.fn()} onUnlinkPullRequest={vi.fn()} @@ -79,14 +80,25 @@ describe('ChecksPanelReviewHeader', () => { expect(markup).not.toContain('lucide-external-link') }) - it('omits the system-browser hint when plain clicks already open externally', () => { - const markup = renderHeader({ showSystemBrowserHint: false }) + it('omits the modifier hint when it lands where a plain click already does', () => { + const markup = renderHeader({ modifierHintDestination: null }) expect(markup).toContain('Open on GitHub') expect(markup).not.toContain('system browser') expect(markup).not.toContain('⇧⌘+click') }) + // Why: with inverting on and Link Routing off the modifier reaches Orca here, so the + // hint must name Orca rather than the destination a plain click already uses. + it('names Orca when the modifier inverts toward the built-in browser', () => { + expect(renderHeader({ modifierHintDestination: 'orca' })).toContain('⇧⌘+click to open in Orca') + + vi.stubGlobal('navigator', { userAgent: 'Windows' }) + expect(renderHeader({ modifierHintDestination: 'orca' })).toContain( + 'Shift+Ctrl+click to open in Orca' + ) + }) + it('shows the Ctrl system-browser hint off macOS', () => { vi.stubGlobal('navigator', { userAgent: 'Windows' }) diff --git a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx index 063aad036..ac5ad3242 100644 --- a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx +++ b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx @@ -28,6 +28,7 @@ import { openHttpLink } from '@/lib/http-link-routing' import { Button } from '@/components/ui/button' import { DetachedHeadBadge } from '@/components/DetachedHeadBadge' import { + getTerminalUrlOrcaBrowserHint, getTerminalUrlSystemBrowserHint, isMacPlatform } from '../terminal-pane/terminal-link-open-hints' @@ -171,7 +172,11 @@ import { stripBaseRef, useCreatePullRequestDialogFields } from './useCreatePullR import { localizedHostedReviewCopy } from '@/i18n/hosted-review-localized-copy' import { translate } from '@/i18n/i18n' import { groupPRComments, type PRCommentGroup } from '@/lib/pr-comment-groups' -import { openChecksPanelHostedReviewUrl } from './checks-panel-hosted-review-click-routing' +import { + openChecksPanelHostedReviewUrl, + resolveChecksPanelHostedReviewModifierDestination, + type ChecksPanelHostedReviewModifierDestination +} from './checks-panel-hosted-review-click-routing' import { ChecksPanelUpdatedAtMetadata } from './checks-panel-updated-at-metadata' import { clearPullRequestGenerationRequiresPushBeforeCreate, @@ -250,7 +255,7 @@ type ChecksPanelReviewHeaderProps = { review: ChecksPanelReview isRefreshing: boolean canUnlinkPullRequest: boolean - showSystemBrowserHint: boolean + modifierHintDestination: ChecksPanelHostedReviewModifierDestination onRefresh: () => void onOpenReview: (event: React.MouseEvent) => void onUnlinkPullRequest: () => void @@ -261,7 +266,7 @@ export function ChecksPanelReviewHeader({ review, isRefreshing, canUnlinkPullRequest, - showSystemBrowserHint, + modifierHintDestination, onRefresh, onOpenReview, onUnlinkPullRequest, @@ -276,9 +281,13 @@ export function ChecksPanelReviewHeader({ 'Open on {{value0}}', { value0: reviewHostLabel } ) - const title = showSystemBrowserHint - ? `${openTitle}. ${getTerminalUrlSystemBrowserHint()}` - : openTitle + const modifierHint = + modifierHintDestination === 'system-browser' + ? getTerminalUrlSystemBrowserHint() + : modifierHintDestination === 'orca' + ? getTerminalUrlOrcaBrowserHint() + : null + const title = modifierHint ? `${openTitle}. ${modifierHint}` : openTitle return (
@@ -3997,11 +4006,10 @@ export default function ChecksPanel(): React.JSX.Element { const reviewShortLabel = activeReview.provider === 'gitlab' ? 'MR' : 'PR' const shouldShowReviewTriageStrip = activeConflictReview !== null || getBrokenChecks(checks).length > 0 - // Why: mirror openHttpLink's routing inputs so the hint only appears when a plain click would open inside Orca. - const showHostedReviewSystemBrowserHint = - Boolean(activeWorktreeId) && - settings?.openLinksInApp === true && - !settings.activeRuntimeEnvironmentId + const hostedReviewModifierHintDestination = resolveChecksPanelHostedReviewModifierDestination( + settings, + Boolean(activeWorktreeId) + ) return (
{/* Why: surface a background-refresh failure over stale cached PR data so a GitHub outage doesn't look like a normal panel. GitHub-only. */} @@ -4020,7 +4028,7 @@ export default function ChecksPanel(): React.JSX.Element { review={activeReview} isRefreshing={isRefreshing} canUnlinkPullRequest={linkedPR !== null} - showSystemBrowserHint={showHostedReviewSystemBrowserHint} + modifierHintDestination={hostedReviewModifierHintDestination} onRefresh={() => void handleRefresh()} onOpenReview={handleOpenPR} onUnlinkPullRequest={handleUnlinkPullRequest} diff --git a/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.test.ts b/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.test.ts index 8c76721cb..956877a7c 100644 --- a/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.test.ts +++ b/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.test.ts @@ -2,7 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { isChecksPanelHostedReviewSystemBrowserModifier, openChecksPanelHostedReviewUrl, - resolveChecksPanelHostedReviewHttpOpenOptions + resolveChecksPanelHostedReviewHttpOpenOptions, + resolveChecksPanelHostedReviewModifierDestination } from './checks-panel-hosted-review-click-routing' const { openHttpLinkMock } = vi.hoisted(() => ({ openHttpLinkMock: vi.fn() })) @@ -16,27 +17,27 @@ beforeEach(() => { }) describe('checks panel hosted review click routing', () => { - it('maps Shift+Cmd to forceSystemBrowser on macOS', () => { + it('maps Shift+Cmd to the routing modifier on macOS', () => { const event = { metaKey: true, ctrlKey: false, shiftKey: true } expect(isChecksPanelHostedReviewSystemBrowserModifier(event, true)).toBe(true) expect(resolveChecksPanelHostedReviewHttpOpenOptions(event, true, 'wt-1')).toEqual({ worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) }) - it('maps Shift+Ctrl to forceSystemBrowser off macOS', () => { + it('maps Shift+Ctrl to the routing modifier off macOS', () => { const event = { metaKey: false, ctrlKey: true, shiftKey: true } expect(isChecksPanelHostedReviewSystemBrowserModifier(event, false)).toBe(true) expect(resolveChecksPanelHostedReviewHttpOpenOptions(event, false, 'wt-1')).toEqual({ worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) }) - it('preserves the worktree id without forceSystemBrowser on plain clicks', () => { + it('preserves the worktree id without the modifier on plain clicks', () => { expect( resolveChecksPanelHostedReviewHttpOpenOptions( { metaKey: false, ctrlKey: false, shiftKey: false }, @@ -46,7 +47,7 @@ describe('checks panel hosted review click routing', () => { ).toEqual({ worktreeId: 'wt-1' }) }) - it('opens hosted review URLs without forceSystemBrowser on plain clicks', () => { + it('opens hosted review URLs without the modifier on plain clicks', () => { openChecksPanelHostedReviewUrl({ url: 'https://github.com/acme/widgets/pull/123', event: { metaKey: false, ctrlKey: false, shiftKey: false }, @@ -59,7 +60,7 @@ describe('checks panel hosted review click routing', () => { }) }) - it('opens hosted review URLs with forceSystemBrowser on Shift+Cmd clicks', () => { + it('opens hosted review URLs with the modifier on Shift+Cmd clicks', () => { openChecksPanelHostedReviewUrl({ url: 'https://github.com/acme/widgets/pull/123', event: { metaKey: true, ctrlKey: false, shiftKey: true }, @@ -69,7 +70,94 @@ describe('checks panel hosted review click routing', () => { expect(openHttpLinkMock).toHaveBeenCalledWith('https://github.com/acme/widgets/pull/123', { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) }) }) + +describe('checks panel hosted review modifier hint destination', () => { + it('names the system browser when a plain click already opens in Orca', () => { + expect(resolveChecksPanelHostedReviewModifierDestination({ openLinksInApp: true }, true)).toBe( + 'system-browser' + ) + }) + + // Why: inverting is inert while links already open in Orca — both meanings of the + // modifier land on the system browser, so checking inverts first would misname it. + it('names the system browser when inverting is on and links already open in Orca', () => { + expect( + resolveChecksPanelHostedReviewModifierDestination( + { openLinksInApp: true, openLinksInAppModifierInverts: true }, + true + ) + ).toBe('system-browser') + }) + + // Why: this is the gesture the invert setting adds — without it the hint stays hidden + // and the only way to reach Orca from this button is undiscoverable. + it('names Orca when inverting is on and links open externally', () => { + expect( + resolveChecksPanelHostedReviewModifierDestination( + { openLinksInApp: false, openLinksInAppModifierInverts: true }, + true + ) + ).toBe('orca') + }) + + it('stays silent while inverting is off and links open externally', () => { + expect( + resolveChecksPanelHostedReviewModifierDestination({ openLinksInApp: false }, true) + ).toBeNull() + expect(resolveChecksPanelHostedReviewModifierDestination(null, true)).toBeNull() + }) + + // Why: openHttpLink refuses to route a remote-owned link into Orca, and openLinksInApp + // cannot apply there either, so neither destination is reachable. + it('stays silent while a remote runtime is active', () => { + expect( + resolveChecksPanelHostedReviewModifierDestination( + { openLinksInApp: true, activeRuntimeEnvironmentId: 'remote-1' }, + true + ) + ).toBeNull() + expect( + resolveChecksPanelHostedReviewModifierDestination( + { + openLinksInApp: false, + openLinksInAppModifierInverts: true, + activeRuntimeEnvironmentId: 'remote-1' + }, + true + ) + ).toBeNull() + }) + + // Why: openHttpLink trims before treating a runtime as active, so a blank id must + // not suppress a hint for a click that still reaches Orca. + it('ignores a blank runtime id', () => { + expect( + resolveChecksPanelHostedReviewModifierDestination( + { + openLinksInApp: false, + openLinksInAppModifierInverts: true, + activeRuntimeEnvironmentId: ' ' + }, + true + ) + ).toBe('orca') + }) + + // Why: openHttpLink gates routing to Orca on a worktree id, so without one the + // modifier lands in the system browser either way. + it('stays silent without a worktree', () => { + expect( + resolveChecksPanelHostedReviewModifierDestination( + { openLinksInApp: false, openLinksInAppModifierInverts: true }, + false + ) + ).toBeNull() + expect( + resolveChecksPanelHostedReviewModifierDestination({ openLinksInApp: true }, false) + ).toBeNull() + }) +}) diff --git a/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.ts b/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.ts index 69954385a..62ddcb71b 100644 --- a/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.ts +++ b/src/renderer/src/components/right-sidebar/checks-panel-hosted-review-click-routing.ts @@ -14,12 +14,41 @@ export function resolveChecksPanelHostedReviewHttpOpenOptions( isMac: boolean, worktreeId: string | null | undefined ): OpenHttpLinkOptions { + // Why: same escape hatch as terminal and markdown links — openHttpLink resolves + // whether it forces the system browser or inverts the Link Routing setting. if (isChecksPanelHostedReviewSystemBrowserModifier(event, isMac)) { - return { worktreeId, forceSystemBrowser: true } + return { worktreeId, modifierHeld: true } } return { worktreeId } } +/** Where a Shift+modifier click lands, or null when it lands where a plain click already does. */ +export type ChecksPanelHostedReviewModifierDestination = 'system-browser' | 'orca' | null + +// Why: mirrors openHttpLink's routing inputs — with inverting on and Link Routing off the +// modifier now reaches Orca here, so gating the hint on openLinksInApp alone hides a live gesture. +export function resolveChecksPanelHostedReviewModifierDestination( + settings: + | { + openLinksInApp?: boolean + openLinksInAppModifierInverts?: boolean + activeRuntimeEnvironmentId?: string | null + } + | null + | undefined, + hasWorktree: boolean +): ChecksPanelHostedReviewModifierDestination { + // Why: trim to match openHttpLink — an untrimmed check hides the hint on a blank + // runtime id while the click still routes to Orca. + if (!hasWorktree || settings?.activeRuntimeEnvironmentId?.trim()) { + return null + } + if (settings?.openLinksInApp === true) { + return 'system-browser' + } + return settings?.openLinksInAppModifierInverts === true ? 'orca' : null +} + export function openChecksPanelHostedReviewUrl({ url, event, diff --git a/src/renderer/src/components/settings/BrowserLinkRoutingModifierSetting.tsx b/src/renderer/src/components/settings/BrowserLinkRoutingModifierSetting.tsx new file mode 100644 index 000000000..aeb8f4151 --- /dev/null +++ b/src/renderer/src/components/settings/BrowserLinkRoutingModifierSetting.tsx @@ -0,0 +1,54 @@ +import type { GlobalSettings } from '../../../../shared/types' +import { SearchableSetting } from './SearchableSetting' +import { SettingsSwitchRow } from './SettingsFormControls' +import { + getLinkRoutingModifierDescription, + getLinkRoutingModifierTitle +} from './browser-link-routing-modifier-copy' + +type BrowserLinkRoutingModifierSettingProps = { + settings: Pick + isMac: boolean + updateSettings: (updates: Partial) => void +} + +export function BrowserLinkRoutingModifierSetting({ + settings, + isMac, + updateSettings +}: BrowserLinkRoutingModifierSettingProps): React.JSX.Element { + const openLinksInApp = settings.openLinksInApp === true + const title = getLinkRoutingModifierTitle(openLinksInApp) + const description = getLinkRoutingModifierDescription({ openLinksInApp, isMac }) + + return ( + + {/* Nested under Link Routing: this row only describes what its modifier does. */} +
+ + updateSettings({ + openLinksInAppModifierInverts: settings.openLinksInAppModifierInverts !== true + }) + } + /> +
+
+ ) +} diff --git a/src/renderer/src/components/settings/BrowserPane.tsx b/src/renderer/src/components/settings/BrowserPane.tsx index 4a75f8fec..d67aaf7ef 100644 --- a/src/renderer/src/components/settings/BrowserPane.tsx +++ b/src/renderer/src/components/settings/BrowserPane.tsx @@ -10,6 +10,7 @@ import { BrowserDefaultZoomSetting } from './BrowserDefaultZoomSetting' import { BrowserUseSetup } from './BrowserUsePane' import { BrowserSearchEngineSetting } from './BrowserSearchEngineSetting' import { BrowserLinkRoutingSetting } from './BrowserLinkRoutingSetting' +import { BrowserLinkRoutingModifierSetting } from './BrowserLinkRoutingModifierSetting' import { BrowserLocalhostWorktreeLabelsSetting } from './BrowserLocalhostWorktreeLabelsSetting' import { BrowserSessionCookiesSection } from './BrowserSessionCookiesSection' import { BrowserNewProfileDialog } from './BrowserNewProfileDialog' @@ -99,11 +100,17 @@ export function BrowserPane({ const showSearchEngine = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[1]]) const showDefaultZoom = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[2]]) const showLinkRouting = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[3]]) - const showLocalhostLabels = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[4]]) - const showCookies = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[5]]) + const showLinkRoutingModifier = matchesSettingsSearch(searchQuery, [ + getBrowserPaneSearchEntries()[4] + ]) + const showLocalhostLabels = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[5]]) + const showCookies = matchesSettingsSearch(searchQuery, [getBrowserPaneSearchEntries()[6]]) const showBrowserUse = matchesSettingsSearch(searchQuery, getBrowserUsePaneSearchEntries()) const isMac = isMacUserAgent() - const linkRoutingDescription = getBrowserLinkRoutingDescription({ isMac }) + const linkRoutingDescription = getBrowserLinkRoutingDescription( + { isMac }, + settings.openLinksInAppModifierInverts === true + ) const hostLabelOverrides = useMemo(() => getHostDisplayLabelOverrides(settings), [settings]) const browserSessionHostOptions = useMemo( () => @@ -238,6 +245,14 @@ export function BrowserPane({ /> ) : null} + {showLinkRoutingModifier ? ( + + ) : null} + {showLocalhostLabels ? ( { - it('uses macOS shortcut symbols for Link Routing copy and search metadata', () => { - expect(getBrowserLinkRoutingShortcutLabel({ isMac: true })).toBe('⇧⌘-click') - - const description = getBrowserLinkRoutingDescription({ isMac: true }) - expect(description).toContain('⇧⌘-click') - expect(description).not.toContain('Cmd/Ctrl') - + it('uses macOS shortcut keywords for Link Routing search metadata', () => { const linkRoutingEntry = getBrowserPaneSearchEntries({ isMac: true }).find( (entry) => entry.title === 'Link Routing' ) - expect(linkRoutingEntry?.description).toBe(description) + expect(linkRoutingEntry?.description).toBe(getBrowserLinkRoutingDescription({ isMac: true })) expect(linkRoutingEntry?.keywords).toContain('cmd') expect(linkRoutingEntry?.keywords).not.toContain('ctrl') @@ -26,18 +20,85 @@ describe('browser settings search copy', () => { expect(defaultZoomEntry?.keywords).toContain('zoom') }) - it('uses Ctrl shortcut text for Link Routing copy and search metadata off macOS', () => { - expect(getBrowserLinkRoutingShortcutLabel({ isMac: false })).toBe('Shift+Ctrl+click') - - const description = getBrowserLinkRoutingDescription({ isMac: false }) - expect(description).toContain('Shift+Ctrl+click') - expect(description).not.toContain('Cmd/Ctrl') - + it('uses Ctrl shortcut keywords for Link Routing search metadata off macOS', () => { const linkRoutingEntry = getBrowserPaneSearchEntries({ isMac: false }).find( (entry) => entry.title === 'Link Routing' ) - expect(linkRoutingEntry?.description).toBe(description) + expect(linkRoutingEntry?.description).toBe(getBrowserLinkRoutingDescription({ isMac: false })) expect(linkRoutingEntry?.keywords).toContain('ctrl') expect(linkRoutingEntry?.keywords).not.toContain('cmd') }) + + // Why: shipping the opt-in must not reword this row for anyone who never enables + // it, so the default output has to stay byte-identical to the pre-feature copy. + it('keeps the pre-feature wording while inverting is off', () => { + expect(getBrowserLinkRoutingDescription({ isMac: true })).toBe( + "Open http(s) links in Orca's built-in browser — from the terminal, markdown, and the editor. ⇧⌘-click always uses your system browser." + ) + expect(getBrowserLinkRoutingDescription({ isMac: false })).toContain( + 'Shift+Ctrl+click always uses your system browser.' + ) + }) + + // Why: "always" would be a lie once the chord can land in Orca, so the nested row + // takes over the claim. + it('drops the modifier claim once inverting is on', () => { + const description = getBrowserLinkRoutingDescription({ isMac: true }, true) + expect(description).not.toContain('click') + expect(description).not.toContain('system browser') + }) +}) + +describe('browser link routing modifier copy', () => { + // Why: BrowserPane gates each row on getBrowserPaneSearchEntries()[n], so a + // reordered or inserted entry silently shows the wrong row for a search. + it('keeps the search entry order BrowserPane indexes by position', () => { + expect(getBrowserPaneSearchEntries({ isMac: true }).map((entry) => entry.title)).toEqual([ + 'Default Home Page', + 'Default Search Engine', + 'Default Zoom', + 'Link Routing', + 'Hold Shift to open in Orca', + 'Localhost Worktree Labels', + 'Session & Cookies' + ]) + }) + + it('names the destination the modifier actually reaches', () => { + expect(getLinkRoutingModifierTitle(false)).toBe('Hold Shift to open in Orca') + expect(getLinkRoutingModifierTitle(true)).toBe('Hold Shift to open in your web browser') + }) + + it('describes the modifier with the platform chord', () => { + expect(getLinkRoutingModifierDescription({ openLinksInApp: false, isMac: true })).toContain( + '⇧⌘' + ) + expect(getLinkRoutingModifierDescription({ openLinksInApp: false, isMac: false })).toContain( + 'Shift+Ctrl' + ) + }) + + it('points the description at Orca only when links currently open externally', () => { + expect(getLinkRoutingModifierDescription({ openLinksInApp: false, isMac: true })).toContain( + "Orca's built-in browser" + ) + expect(getLinkRoutingModifierDescription({ openLinksInApp: true, isMac: true })).toContain( + 'system browser' + ) + }) + + // Why: the toggle is off by default, so present-tense "opens one in Orca" would + // describe behavior the user does not have yet. + it('phrases the Orca branch as enabled-state copy', () => { + expect(getLinkRoutingModifierDescription({ openLinksInApp: false, isMac: true })).toContain( + 'When enabled' + ) + }) + + // Why: the entry is built with openLinksInApp false, so without this the row is + // unfindable by the title it actually renders when Link Routing is on. + it('indexes both titles so the row is findable in either routing state', () => { + const entry = getBrowserPaneSearchEntries({ isMac: true })[4] + expect(entry?.keywords).toContain(getLinkRoutingModifierTitle(true)) + }) }) diff --git a/src/renderer/src/components/settings/browser-search.ts b/src/renderer/src/components/settings/browser-search.ts index 4cd99f7fa..a9b204441 100644 --- a/src/renderer/src/components/settings/browser-search.ts +++ b/src/renderer/src/components/settings/browser-search.ts @@ -1,6 +1,10 @@ import type { SettingsSearchEntry } from './settings-search' import { translate } from '@/i18n/i18n' import { translateSearchKeyword } from './settings-search-keywords' +import { + getLinkRoutingModifierDescription, + getLinkRoutingModifierTitle +} from './browser-link-routing-modifier-copy' type BrowserShortcutPlatform = { isMac: boolean @@ -12,12 +16,17 @@ function getDefaultBrowserShortcutPlatform(): BrowserShortcutPlatform { } } -export function getBrowserLinkRoutingShortcutLabel(platform: BrowserShortcutPlatform): string { - return platform.isMac ? '⇧⌘-click' : 'Shift+Ctrl+click' -} - -export function getBrowserLinkRoutingDescription(platform: BrowserShortcutPlatform): string { - return `Open http(s) links in Orca's built-in browser — from the terminal, markdown, and the editor. ${getBrowserLinkRoutingShortcutLabel(platform)} always uses your system browser.` +// Why: "always" stops being true once inverting is on, so only then does the nested +// row take over the chord sentence — with it off this reads exactly as it always has. +export function getBrowserLinkRoutingDescription( + platform: BrowserShortcutPlatform = getDefaultBrowserShortcutPlatform(), + modifierInverts = false +): string { + const base = + "Open http(s) links in Orca's built-in browser — from the terminal, markdown, and the editor." + return modifierInverts + ? base + : `${base} ${platform.isMac ? '⇧⌘-click' : 'Shift+Ctrl+click'} always uses your system browser.` } export function getBrowserPaneSearchEntries( @@ -109,6 +118,38 @@ export function getBrowserPaneSearchEntries( ...translateSearchKeyword('auto.components.settings.browser.search.a7a07d5415', 'editor') ] }, + { + title: getLinkRoutingModifierTitle(false), + description: getLinkRoutingModifierDescription({ + openLinksInApp: false, + isMac: platform.isMac + }), + keywords: [ + ...translateSearchKeyword('auto.components.settings.browser.search.2d2d995c58', 'browser'), + ...translateSearchKeyword('auto.components.settings.browser.search.bea27bac4b', 'links'), + ...translateSearchKeyword('auto.components.settings.browser.search.90425d313c', 'shift'), + ...translateSearchKeyword( + 'auto.components.settings.browser.search.linkRoutingModifier.routing', + 'routing' + ), + ...translateSearchKeyword( + 'auto.components.settings.browser.search.linkRoutingModifier.modifier', + 'modifier' + ), + ...translateSearchKeyword( + 'auto.components.settings.browser.search.linkRoutingModifier.invert', + 'invert' + ), + ...translateSearchKeyword( + 'auto.components.settings.browser.search.linkRoutingModifier.opposite', + 'opposite' + ), + // Why: the row renders live copy but this entry is built with openLinksInApp + // false, so index the other title too or the row is unfindable by its own text. + getLinkRoutingModifierTitle(true), + platform.isMac ? 'cmd' : 'ctrl' + ] + }, { title: translate( 'auto.components.settings.browser.search.19ea5607cf', diff --git a/src/renderer/src/components/terminal-pane/edge-wrapped-terminal-http-links.test.ts b/src/renderer/src/components/terminal-pane/edge-wrapped-terminal-http-links.test.ts index 9289f67b7..7f62f00ed 100644 --- a/src/renderer/src/components/terminal-pane/edge-wrapped-terminal-http-links.test.ts +++ b/src/renderer/src/components/terminal-pane/edge-wrapped-terminal-http-links.test.ts @@ -76,7 +76,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -86,7 +86,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 3, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -111,7 +111,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -121,7 +121,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 1, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -136,7 +136,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -146,7 +146,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 2, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(false) expect(openUrlMock).not.toHaveBeenCalled() @@ -163,7 +163,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -173,7 +173,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 2, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(false) expect(openUrlMock).not.toHaveBeenCalled() @@ -189,7 +189,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -199,7 +199,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -218,7 +218,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -228,7 +228,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 20, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -245,7 +245,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 4, y: 2 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -268,7 +268,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 191, y: 1 }, cols, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -278,7 +278,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 10, y: rows.length }, cols, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -298,7 +298,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -308,7 +308,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 5, y: rowTexts.length }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -342,7 +342,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 5, y: rowTexts.length }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -361,7 +361,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 11, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -377,7 +377,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: firstRow.indexOf('https') + 8, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() @@ -394,7 +394,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 10, y: 1 }, COLS, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(false) expect(openUrlMock).not.toHaveBeenCalled() @@ -416,7 +416,7 @@ describe('edge-wrapped terminal HTTP links', () => { expect( openHttpLinkAtBufferPosition(buffer, { x: 10, y: 1 }, cols, { worktreeId: 'wt-1', - forceSystemBrowser: true + modifierHeld: true }) ).toBe(true) expect(openUrlMock).toHaveBeenCalledOnce() diff --git a/src/renderer/src/components/terminal-pane/repro-8832-url-next-line.test.ts b/src/renderer/src/components/terminal-pane/repro-8832-url-next-line.test.ts index 14fbe14aa..067fc46f9 100644 --- a/src/renderer/src/components/terminal-pane/repro-8832-url-next-line.test.ts +++ b/src/renderer/src/components/terminal-pane/repro-8832-url-next-line.test.ts @@ -80,7 +80,7 @@ function openUrlAt( openUrlMock.mockReset() const opened = openHttpLinkAtBufferPosition(buffer, { x, y }, cols, { worktreeId: 'wt-repro-8832', - forceSystemBrowser: true + modifierHeld: true }) return { opened, url: openUrlMock.mock.calls[0]?.[0] as string | undefined } } diff --git a/src/renderer/src/components/terminal-pane/terminal-link-open-hints.test.ts b/src/renderer/src/components/terminal-pane/terminal-link-open-hints.test.ts new file mode 100644 index 000000000..656db8d4b --- /dev/null +++ b/src/renderer/src/components/terminal-pane/terminal-link-open-hints.test.ts @@ -0,0 +1,89 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { getTerminalUrlOpenHint, terminalUrlOpenHintOptionsFor } from './terminal-link-open-hints' + +function stubPlatform(isMac: boolean): void { + vi.stubGlobal('navigator', { userAgent: isMac ? 'Mac OS X' : 'Windows NT 10.0' }) +} + +afterEach(() => { + vi.unstubAllGlobals() +}) + +describe('getTerminalUrlOpenHint', () => { + it('keeps the system-browser wording by default', () => { + stubPlatform(true) + expect(getTerminalUrlOpenHint()).toBe('⌘+click to open or ⇧⌘+click for system browser') + }) + + it('keeps the system-browser wording when inverting is off', () => { + stubPlatform(true) + expect(getTerminalUrlOpenHint({ openLinksInApp: false, modifierInverts: false })).toContain( + 'for system browser' + ) + }) + + // Why: with links already opening in Orca, inverting still lands on the system + // browser, so the hint must not promise Orca. + it('keeps the system-browser wording when inverting but links open in Orca', () => { + stubPlatform(true) + expect(getTerminalUrlOpenHint({ openLinksInApp: true, modifierInverts: true })).toContain( + 'for system browser' + ) + }) + + it('names Orca when inverting and links open externally', () => { + stubPlatform(true) + expect(getTerminalUrlOpenHint({ openLinksInApp: false, modifierInverts: true })).toBe( + '⌘+click to open or ⇧⌘+click to open in Orca' + ) + }) + + it('uses the Ctrl chord off macOS', () => { + stubPlatform(false) + expect(getTerminalUrlOpenHint({ openLinksInApp: false, modifierInverts: true })).toBe( + 'Ctrl+click to open or Shift+Ctrl+click to open in Orca' + ) + }) +}) + +describe('terminalUrlOpenHintOptionsFor', () => { + it('reports inversion when links open externally on a local runtime', () => { + expect( + terminalUrlOpenHintOptionsFor({ + openLinksInApp: false, + openLinksInAppModifierInverts: true + }) + ).toEqual({ openLinksInApp: false, modifierInverts: true }) + }) + + // Why: openHttpLink refuses to route a remote-owned URL into Orca, so promising + // "open in Orca" there would advertise a click that lands somewhere else. + it('drops inversion while a remote runtime is active', () => { + stubPlatform(true) + const options = terminalUrlOpenHintOptionsFor({ + openLinksInApp: false, + openLinksInAppModifierInverts: true, + activeRuntimeEnvironmentId: 'remote-1' + }) + + expect(options.modifierInverts).toBe(false) + expect(getTerminalUrlOpenHint(options)).toContain('for system browser') + }) + + it('ignores a blank runtime id', () => { + expect( + terminalUrlOpenHintOptionsFor({ + openLinksInApp: false, + openLinksInAppModifierInverts: true, + activeRuntimeEnvironmentId: ' ' + }).modifierInverts + ).toBe(true) + }) + + it('tolerates missing settings', () => { + expect(terminalUrlOpenHintOptionsFor(null)).toEqual({ + openLinksInApp: false, + modifierInverts: false + }) + }) +}) diff --git a/src/renderer/src/components/terminal-pane/terminal-link-open-hints.ts b/src/renderer/src/components/terminal-pane/terminal-link-open-hints.ts index 0d51669a6..0bdf05c61 100644 --- a/src/renderer/src/components/terminal-pane/terminal-link-open-hints.ts +++ b/src/renderer/src/components/terminal-pane/terminal-link-open-hints.ts @@ -20,7 +20,40 @@ export function getTerminalHtmlFileOpenHint(): string { : 'Ctrl+click to open or Shift+Ctrl+click for default browser' } -export function getTerminalUrlOpenHint(): string { +export type TerminalUrlOpenHintOptions = { + openLinksInApp?: boolean + modifierInverts?: boolean +} + +// Why: openHttpLink only routes to Orca when the source is local, so a remote runtime +// pins every link to the system browser and inverting cannot reach Orca there. +export function terminalUrlOpenHintOptionsFor( + settings: + | { + openLinksInApp?: boolean + openLinksInAppModifierInverts?: boolean + activeRuntimeEnvironmentId?: string | null + } + | null + | undefined +): TerminalUrlOpenHintOptions { + return { + openLinksInApp: settings?.openLinksInApp === true, + modifierInverts: + settings?.openLinksInAppModifierInverts === true && + !settings?.activeRuntimeEnvironmentId?.trim() + } +} + +// Why: with modifierInverts on, Shift no longer always means "system browser" — +// it means "the other one" — so the hint has to name the actual destination. +export function getTerminalUrlOpenHint(options: TerminalUrlOpenHintOptions = {}): string { + const invertsToOrca = options.modifierInverts === true && options.openLinksInApp !== true + if (invertsToOrca) { + return isMacPlatform() + ? '⌘+click to open or ⇧⌘+click to open in Orca' + : 'Ctrl+click to open or Shift+Ctrl+click to open in Orca' + } return isMacPlatform() ? '⌘+click to open or ⇧⌘+click for system browser' : 'Ctrl+click to open or Shift+Ctrl+click for system browser' @@ -30,6 +63,12 @@ export function getTerminalUrlSystemBrowserHint(): string { return isMacPlatform() ? '⇧⌘+click for system browser' : 'Shift+Ctrl+click for system browser' } +// Why: the mirror of the system-browser hint for surfaces where inverting sends the +// modifier the other way; a plain click there already opens the system browser. +export function getTerminalUrlOrcaBrowserHint(): string { + return isMacPlatform() ? '⇧⌘+click to open in Orca' : 'Shift+Ctrl+click to open in Orca' +} + export function getTerminalWorktreePathOpenHint(canOpenWithSystemDefault: boolean): string { if (!canOpenWithSystemDefault) { return isMacPlatform() ? '⌘+click to switch workspace' : 'Ctrl+click to switch workspace' diff --git a/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts b/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts index ea1eff1b2..c51eedbd5 100644 --- a/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts +++ b/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts @@ -81,7 +81,7 @@ export function handleOscLink( if (parsed.protocol === 'http:' || parsed.protocol === 'https:') { openTerminalHttpLink(parsed.toString(), { worktreeId: deps.worktreeId, - forceSystemBrowser: Boolean(event?.shiftKey), + modifierHeld: Boolean(event?.shiftKey), requestOpenLinksInAppPreference: deps.requestOpenLinksInAppPreference }) return true diff --git a/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts b/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts index 3a6e2c1f2..d38ce6d93 100644 --- a/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts +++ b/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts @@ -11,7 +11,7 @@ import { buildWrappedLogicalLine, rangeForParsedFileLink } from './wrapped-termi type UrlLinkHitTestDeps = { worktreeId: string - forceSystemBrowser?: boolean + modifierHeld?: boolean requestOpenLinksInAppPreference?: TerminalLinkRoutingPreferenceRequester } @@ -225,7 +225,7 @@ export function installHttpLinkClickFallback( // never established, while defaultPrevented avoids duplicate opens. const opened = openHttpLinkAtTerminalMouseEvent(terminal, event, { worktreeId: deps.worktreeId, - forceSystemBrowser: event.shiftKey, + modifierHeld: event.shiftKey, requestOpenLinksInAppPreference: deps.requestOpenLinksInAppPreference }) if (opened) { @@ -303,8 +303,10 @@ function rangeContainsBufferPosition( } export function openTerminalHttpLink(url: string, deps: UrlLinkHitTestDeps): void { - if (deps.forceSystemBrowser) { - openHttpLink(url, { worktreeId: deps.worktreeId, forceSystemBrowser: true }) + if (deps.modifierHeld) { + // Why: the modifier states a destination outright, so it also skips the + // one-time routing prompt; openHttpLink resolves which destination it means. + openHttpLink(url, { worktreeId: deps.worktreeId, modifierHeld: true }) return } diff --git a/src/renderer/src/components/terminal-pane/terminal-web-link-click.ts b/src/renderer/src/components/terminal-pane/terminal-web-link-click.ts index c512cc841..96b7d3ff0 100644 --- a/src/renderer/src/components/terminal-pane/terminal-web-link-click.ts +++ b/src/renderer/src/components/terminal-pane/terminal-web-link-click.ts @@ -29,7 +29,7 @@ export function handleTerminalWebLinkClick( deps.terminal && openHttpLinkAtTerminalMouseEvent(deps.terminal, event, { worktreeId: deps.worktreeId, - forceSystemBrowser: Boolean(event.shiftKey), + modifierHeld: Boolean(event.shiftKey), requestOpenLinksInAppPreference: deps.requestOpenLinksInAppPreference }) ) { diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts index 0f7199c48..402aab3b3 100644 --- a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts +++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts @@ -32,6 +32,7 @@ import { getTerminalUrlOpenHint, installFilePathLinkClickFallback } from './terminal-link-handlers' +import { terminalUrlOpenHintOptionsFor } from './terminal-link-open-hints' import { createTerminalHandleLinkProvider } from './terminal-handle-links' import type { LinkHandlerDeps } from './terminal-link-handlers' import { handleOscLink } from './terminal-osc-link-routing' @@ -831,7 +832,9 @@ export function useTerminalPaneLifecycle({ }) const fileOpenLinkHint = getTerminalFileOpenHint() - const urlOpenLinkHint = getTerminalUrlOpenHint() + // Why: read settingsRef at fire time so toggling link routing applies without recreating panes. + const getUrlOpenLinkHint = (): string => + getTerminalUrlOpenHint(terminalUrlOpenHintOptionsFor(settingsRef.current)) const osc7UncHost = extractUncHost(startupCwd) let releaseWebviewDragPassthrough: (() => void) | null = null @@ -1133,6 +1136,7 @@ export function useTerminalPaneLifecycle({ hover: (_event, text) => { oscTooltipHoverToken += 1 const hoverToken = oscTooltipHoverToken + const urlOpenLinkHint = getUrlOpenLinkHint() pane.linkTooltip.textContent = `${text} (${urlOpenLinkHint})` pane.linkTooltip.style.display = '' void formatTerminalUrlTooltip(text, urlOpenLinkHint).then((nextText) => { @@ -1442,6 +1446,7 @@ export function useTerminalPaneLifecycle({ requestOpenLinksInAppPreference }) }, + linkOpenHint: getUrlOpenLinkHint, formatLinkTooltip: (url, openLinkHint) => formatTerminalUrlTooltip(url, openLinkHint), // Why: hidden panes stay mounted so PTYs survive navigation, but their WebGL contexts drain Chromium's budget and can blank visible panes. initialRenderingSuspended: !isVisibleRef.current, diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 191f9288c..fe74e5abe 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -7709,6 +7709,12 @@ "8dd4805991": "file", "68d1db8929": "markdown", "90425d313c": "shift", + "linkRoutingModifier": { + "routing": "routing", + "modifier": "modifier", + "invert": "invert", + "opposite": "opposite" + }, "72c58f7792": "webview", "82ba1c80ea": "localhost", "bea27bac4b": "links", @@ -9573,6 +9579,12 @@ "unpackedHelp": "Development builds must be updated from their source checkout.", "legacyHelp": "Update this server manually once to enable remote updates." }, + "BrowserLinkRoutingModifierSetting": { + "titleSystem": "Hold Shift to open in your web browser", + "titleOrca": "Hold Shift to open in Orca", + "descriptionSystem": "Links open in Orca, so {{chord}}+click sends one to your system browser instead.", + "descriptionOrca": "Links open in your system browser. When enabled, {{chord}}+click opens one in Orca's built-in browser instead." + }, "PluginConsentDialog": { "workerTrust": "Background worker — runs its own process", "instructionalTrust": "Instructional content — runs later under user or agent authority", diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index 9643feb46..83e2bd96e 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -7649,6 +7649,12 @@ "8dd4805991": "archivo", "68d1db8929": "markdown", "90425d313c": "cambio", + "linkRoutingModifier": { + "routing": "enrutamiento", + "modifier": "modificador", + "invert": "invertir", + "opposite": "opuesto" + }, "72c58f7792": "vista web", "82ba1c80ea": "localhost", "bea27bac4b": "enlaces", @@ -9550,6 +9556,12 @@ "unpackedHelp": "Development builds must be updated from their source checkout.", "legacyHelp": "Update this server manually once to enable remote updates." }, + "BrowserLinkRoutingModifierSetting": { + "titleSystem": "Hold Shift to open in your web browser", + "titleOrca": "Hold Shift to open in Orca", + "descriptionSystem": "Links open in Orca, so {{chord}}+click sends one to your system browser instead.", + "descriptionOrca": "Links open in your system browser. When enabled, {{chord}}+click opens one in Orca's built-in browser instead." + }, "PluginConsentDialog": { "workerTrust": "Proceso en segundo plano — se ejecuta en su propio proceso", "instructionalTrust": "Contenido instructivo — se ejecuta más tarde con la autoridad del usuario o del agente", diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 5ff8b4eaf..3d5da6f65 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -7671,6 +7671,12 @@ "8dd4805991": "ファイル", "68d1db8929": "markdown", "90425d313c": "シフト", + "linkRoutingModifier": { + "routing": "ルーティング", + "modifier": "修飾キー", + "invert": "反転", + "opposite": "逆" + }, "72c58f7792": "ウェブビュー", "82ba1c80ea": "ローカルホスト", "bea27bac4b": "リンク", @@ -9550,6 +9556,12 @@ "unpackedHelp": "開発ビルドはソースチェックアウトから更新する必要があります。", "legacyHelp": "リモート更新を有効にするには、このサーバーを手動で一度更新してください。" }, + "BrowserLinkRoutingModifierSetting": { + "titleSystem": "Hold Shift to open in your web browser", + "titleOrca": "Hold Shift to open in Orca", + "descriptionSystem": "Links open in Orca, so {{chord}}+click sends one to your system browser instead.", + "descriptionOrca": "Links open in your system browser. When enabled, {{chord}}+click opens one in Orca's built-in browser instead." + }, "PluginConsentDialog": { "workerTrust": "バックグラウンドワーカー — 自身のプロセスを実行", "instructionalTrust": "インストラクショナルコンテンツ — ユーザーまたはエージェントの権限で後から実行", diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index 1d558297c..6732151a1 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -7634,6 +7634,12 @@ "8dd4805991": "파일", "68d1db8929": "markdown", "90425d313c": "Shift", + "linkRoutingModifier": { + "routing": "라우팅", + "modifier": "수정자", + "invert": "반전", + "opposite": "반대" + }, "72c58f7792": "웹뷰", "82ba1c80ea": "로컬호스트", "bea27bac4b": "링크", @@ -9550,6 +9556,12 @@ "unpackedHelp": "개발 빌드는 소스 체크아웃에서 업데이트해야 합니다.", "legacyHelp": "원격 업데이트를 활성화하려면 이 서버를 수동으로 한 번 업데이트하세요." }, + "BrowserLinkRoutingModifierSetting": { + "titleSystem": "Hold Shift to open in your web browser", + "titleOrca": "Hold Shift to open in Orca", + "descriptionSystem": "Links open in Orca, so {{chord}}+click sends one to your system browser instead.", + "descriptionOrca": "Links open in your system browser. When enabled, {{chord}}+click opens one in Orca's built-in browser instead." + }, "PluginConsentDialog": { "workerTrust": "백그라운드 워커 — 자체 프로세스 실행", "instructionalTrust": "지시 내용 — 사용자 또는 에이전트 권한으로 나중에 실행", diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index 7b392c8c1..91b582b22 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -7634,6 +7634,12 @@ "8dd4805991": "文件", "68d1db8929": "markdown", "90425d313c": "转移", + "linkRoutingModifier": { + "routing": "路由", + "modifier": "修饰键", + "invert": "反转", + "opposite": "相反" + }, "72c58f7792": "网页视图", "82ba1c80ea": "本地主机", "bea27bac4b": "链接", @@ -9550,6 +9556,12 @@ "unpackedHelp": "Development builds must be updated from their source checkout.", "legacyHelp": "Update this server manually once to enable remote updates." }, + "BrowserLinkRoutingModifierSetting": { + "titleSystem": "Hold Shift to open in your web browser", + "titleOrca": "Hold Shift to open in Orca", + "descriptionSystem": "Links open in Orca, so {{chord}}+click sends one to your system browser instead.", + "descriptionOrca": "Links open in your system browser. When enabled, {{chord}}+click opens one in Orca's built-in browser instead." + }, "PluginConsentDialog": { "workerTrust": "后台工作进程 — 运行自己的进程", "instructionalTrust": "指令内容 — 在用户或智能体权限下运行", diff --git a/src/renderer/src/lib/http-link-modifier-routing.test.ts b/src/renderer/src/lib/http-link-modifier-routing.test.ts new file mode 100644 index 000000000..b37a900cd --- /dev/null +++ b/src/renderer/src/lib/http-link-modifier-routing.test.ts @@ -0,0 +1,51 @@ +import { describe, expect, it } from 'vitest' +import { resolveModifierRouting } from './http-link-routing' + +describe('resolveModifierRouting', () => { + it('is inert without the modifier regardless of settings', () => { + for (const openLinksInApp of [true, false]) { + for (const inverts of [true, false]) { + expect(resolveModifierRouting(false, openLinksInApp, inverts)).toEqual({ + wantsOrca: false, + wantsSystemBrowser: false + }) + } + } + }) + + // Why: the setting ships off, so the historical one-way escape hatch must be + // byte-for-byte unchanged for every existing user. + it('always forces the system browser when inverting is off', () => { + expect(resolveModifierRouting(true, true, false)).toEqual({ + wantsOrca: false, + wantsSystemBrowser: true + }) + expect(resolveModifierRouting(true, false, false)).toEqual({ + wantsOrca: false, + wantsSystemBrowser: true + }) + }) + + it('still reaches the system browser when inverting and links open in Orca', () => { + expect(resolveModifierRouting(true, true, true)).toEqual({ + wantsOrca: false, + wantsSystemBrowser: true + }) + }) + + it('reaches Orca when inverting and links open in the system browser', () => { + expect(resolveModifierRouting(true, false, true)).toEqual({ + wantsOrca: true, + wantsSystemBrowser: false + }) + }) + + it('only diverges from the legacy behavior when links open externally', () => { + expect(resolveModifierRouting(true, true, true)).toEqual( + resolveModifierRouting(true, true, false) + ) + expect(resolveModifierRouting(true, false, true)).not.toEqual( + resolveModifierRouting(true, false, false) + ) + }) +}) diff --git a/src/renderer/src/lib/http-link-routing.test.ts b/src/renderer/src/lib/http-link-routing.test.ts index 56ddc9b6e..86c3bc18c 100644 --- a/src/renderer/src/lib/http-link-routing.test.ts +++ b/src/renderer/src/lib/http-link-routing.test.ts @@ -16,6 +16,7 @@ const storeState = { settings: undefined as | { openLinksInApp?: boolean + openLinksInAppModifierInverts?: boolean openLinksInAppPreferencePrompted?: boolean activeRuntimeEnvironmentId?: string | null localhostWorktreeLabelsEnabled?: boolean @@ -380,3 +381,78 @@ describe('openHttpLink', () => { expect(registerLocalhostLabelMock).not.toHaveBeenCalled() }) }) + +describe('openHttpLink modifier routing', () => { + it('forces the system browser when inverting is off and links open in Orca', () => { + storeState.settings = { openLinksInApp: true, openLinksInAppModifierInverts: false } + + openHttpLink('https://example.com/', { worktreeId: 'wt-1', modifierHeld: true }) + + expect(openUrlMock).toHaveBeenCalledWith('https://example.com/') + expect(createBrowserTabMock).not.toHaveBeenCalled() + }) + + // Why: this is the pre-existing dead gesture — Shift already meant "system + // browser", which is where the link was going anyway. + it('stays on the system browser when inverting is off and links open externally', () => { + storeState.settings = { openLinksInApp: false, openLinksInAppModifierInverts: false } + + openHttpLink('https://example.com/', { worktreeId: 'wt-1', modifierHeld: true }) + + expect(openUrlMock).toHaveBeenCalledWith('https://example.com/') + expect(createBrowserTabMock).not.toHaveBeenCalled() + }) + + it('opens in Orca when inverting is on and links open externally', () => { + storeState.settings = { openLinksInApp: false, openLinksInAppModifierInverts: true } + + openHttpLink('https://example.com/', { worktreeId: 'wt-1', modifierHeld: true }) + + expect(setActiveWorktreeMock).toHaveBeenCalledWith('wt-1') + expect(createBrowserTabMock).toHaveBeenCalledWith('wt-1', 'https://example.com/', { + activate: true + }) + expect(openUrlMock).not.toHaveBeenCalled() + }) + + it('opens in the system browser when inverting is on and links open in Orca', () => { + storeState.settings = { openLinksInApp: true, openLinksInAppModifierInverts: true } + + openHttpLink('https://example.com/', { worktreeId: 'wt-1', modifierHeld: true }) + + expect(openUrlMock).toHaveBeenCalledWith('https://example.com/') + expect(createBrowserTabMock).not.toHaveBeenCalled() + }) + + it('leaves unmodified clicks on the setting', () => { + storeState.settings = { openLinksInApp: false, openLinksInAppModifierInverts: true } + + openHttpLink('https://example.com/', { worktreeId: 'wt-1' }) + + expect(openUrlMock).toHaveBeenCalledWith('https://example.com/') + expect(createBrowserTabMock).not.toHaveBeenCalled() + }) + + // Why: remote-owned links must never land in an Orca tab that cannot reach them. + it('never routes a remote source into Orca even when inverting', () => { + storeState.settings = { openLinksInApp: false, openLinksInAppModifierInverts: true } + + openHttpLink('https://example.com/', { + worktreeId: 'wt-1', + modifierHeld: true, + sourceOwner: { kind: 'ssh', connectionId: 'conn-1' } + }) + + expect(openUrlMock).toHaveBeenCalledWith('https://example.com/') + expect(createBrowserTabMock).not.toHaveBeenCalled() + }) + + it('keeps forceSystemBrowser unconditional', () => { + storeState.settings = { openLinksInApp: true, openLinksInAppModifierInverts: true } + + openHttpLink('https://example.com/', { worktreeId: 'wt-1', forceSystemBrowser: true }) + + expect(openUrlMock).toHaveBeenCalledWith('https://example.com/') + expect(createBrowserTabMock).not.toHaveBeenCalled() + }) +}) diff --git a/src/renderer/src/lib/http-link-routing.ts b/src/renderer/src/lib/http-link-routing.ts index e3a34faa4..06cc0d523 100644 --- a/src/renderer/src/lib/http-link-routing.ts +++ b/src/renderer/src/lib/http-link-routing.ts @@ -8,7 +8,10 @@ import type { WorkspacePort, WorkspacePortScanResult } from '../../../shared/wor export type OpenHttpLinkOptions = { worktreeId?: string | null + /** Unconditional: always use the system browser regardless of settings. */ forceSystemBrowser?: boolean + /** The Shift escape-hatch modifier was held; resolveModifierRouting decides what it means. */ + modifierHeld?: boolean sourceOwner?: HttpLinkSourceOwner } @@ -22,7 +25,10 @@ type StoreAccessor = () => { settings?: Partial< Pick< GlobalSettings, - 'openLinksInApp' | 'activeRuntimeEnvironmentId' | 'localhostWorktreeLabelsEnabled' + | 'openLinksInApp' + | 'openLinksInAppModifierInverts' + | 'activeRuntimeEnvironmentId' + | 'localhostWorktreeLabelsEnabled' > > | null setActiveWorktree: (worktreeId: string) => void @@ -61,21 +67,49 @@ export function registerHttpLinkStoreAccessor(fn: StoreAccessor): void { // Scope: http(s) URLs only. file: URIs and in-worktree markdown targets are // owned by resolveMarkdownLinkTarget and must stay on that path — this helper // is only invoked on target.kind === 'external' (and for the terminal's http -// branch). Shift+Cmd/Ctrl is the escape hatch: callers pass forceSystemBrowser -// to bypass the setting entirely. +// branch). Shift+Cmd/Ctrl is the escape hatch: click handlers pass modifierHeld +// so resolveModifierRouting applies it; forceSystemBrowser stays reserved for +// callers that must bypass the setting unconditionally. +/** + * Resolves what the Shift modifier means for one click. Historically it always + * forced the system browser, which is a no-op when that is already the default; + * openLinksInAppModifierInverts makes it flip whichever way Link Routing points + * so the other destination is always one click away. + */ +export function resolveModifierRouting( + modifierHeld: boolean, + openLinksInApp: boolean, + modifierInverts: boolean +): { wantsOrca: boolean; wantsSystemBrowser: boolean } { + if (!modifierHeld) { + return { wantsOrca: false, wantsSystemBrowser: false } + } + if (!modifierInverts) { + return { wantsOrca: false, wantsSystemBrowser: true } + } + return { wantsOrca: !openLinksInApp, wantsSystemBrowser: openLinksInApp } +} + export function openHttpLink(url: string, opts: OpenHttpLinkOptions = {}): void { - const { worktreeId, forceSystemBrowser, sourceOwner } = opts + const { worktreeId, forceSystemBrowser, modifierHeld, sourceOwner } = opts if (sourceOwner?.kind === 'unknown') { return } const state = storeAccessor?.() const remoteRuntimeActive = Boolean(state?.settings?.activeRuntimeEnvironmentId?.trim()) const sourceIsLocal = sourceOwner ? sourceOwner.kind === 'local' : !remoteRuntimeActive + const openLinksInApp = state?.settings?.openLinksInApp === true + const modifier = resolveModifierRouting( + Boolean(modifierHeld), + openLinksInApp, + state?.settings?.openLinksInAppModifierInverts === true + ) const routeToOrca = sourceIsLocal && !forceSystemBrowser && + !modifier.wantsSystemBrowser && Boolean(worktreeId) && - state?.settings?.openLinksInApp === true + (openLinksInApp || modifier.wantsOrca) if (routeToOrca && worktreeId && state) { // Why: http clicks from inside a worktree should not push a worktree-switch diff --git a/src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts b/src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts index d4aa34759..13e36a962 100644 --- a/src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts +++ b/src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts @@ -1,5 +1,5 @@ // @vitest-environment happy-dom -import { afterEach, describe, expect, it, vi } from 'vitest' +import { describe, expect, it, vi } from 'vitest' import type { TerminalLeafId } from '../../../../shared/stable-pane-id' import { createPaneDOM } from './pane-dom-creation' @@ -48,21 +48,13 @@ vi.mock('@xterm/xterm', () => ({ }) })) -function setPlatform(userAgent: string): void { - vi.stubGlobal('navigator', { userAgent }) -} - -afterEach(() => { - vi.unstubAllGlobals() -}) - describe('createPaneDOM link tooltips', () => { it('anchors WebLinks hover text to the unpadded terminal window corner', () => { const leafId = '11111111-1111-4111-8111-111111111111' as TerminalLeafId const pane = createPaneDOM( 1, leafId, - {}, + { linkOpenHint: () => 'open hint' }, { active: null } as never, {} as never, vi.fn(), @@ -77,38 +69,27 @@ describe('createPaneDOM link tooltips', () => { expect(pane.linkTooltip.style.display).toBe('none') }) - it('uses desktop modifier-click text for WebLinks hover hints', () => { + // Why: the caller owns the hint, so dropping the wiring is a compile error rather + // than a silent fall back to stale copy. + it('re-resolves the caller hint on every hover so setting changes apply live', () => { const leafId = '11111111-1111-4111-8111-111111111111' as TerminalLeafId - - setPlatform('Macintosh') - const macPane = createPaneDOM( + let hint = 'first hint' + const pane = createPaneDOM( 1, leafId, - {}, + { linkOpenHint: () => hint }, { active: null } as never, {} as never, vi.fn(), vi.fn() ) - webLinksAddonMock.options?.hover?.({} as MouseEvent, 'http://localhost:5180/') - expect(macPane.linkTooltip.textContent).toBe( - 'http://localhost:5180/ (⌘+click to open or ⇧⌘+click for system browser)' - ) - setPlatform('Windows') - const windowsPane = createPaneDOM( - 2, - leafId, - {}, - { active: null } as never, - {} as never, - vi.fn(), - vi.fn() - ) webLinksAddonMock.options?.hover?.({} as MouseEvent, 'http://localhost:5180/') - expect(windowsPane.linkTooltip.textContent).toBe( - 'http://localhost:5180/ (Ctrl+click to open or Shift+Ctrl+click for system browser)' - ) + expect(pane.linkTooltip.textContent).toBe('http://localhost:5180/ (first hint)') + + hint = 'second hint' + webLinksAddonMock.options?.hover?.({} as MouseEvent, 'http://localhost:5180/') + expect(pane.linkTooltip.textContent).toBe('http://localhost:5180/ (second hint)') }) it('lets callers replace WebLinks hover text for display-only labels', async () => { @@ -118,6 +99,7 @@ describe('createPaneDOM link tooltips', () => { 1, leafId, { + linkOpenHint: () => 'open hint', formatLinkTooltip: async () => labeledText }, { active: null } as never, diff --git a/src/renderer/src/lib/pane-manager/pane-dom-creation.ts b/src/renderer/src/lib/pane-manager/pane-dom-creation.ts index 7c2fa26fa..089e590a0 100644 --- a/src/renderer/src/lib/pane-manager/pane-dom-creation.ts +++ b/src/renderer/src/lib/pane-manager/pane-dom-creation.ts @@ -15,12 +15,6 @@ import { ENABLE_WEBGL_RENDERER } from './pane-webgl-renderer' import { installGuardedLinkProviderRegistration } from './terminal-link-provider-guard' import { installWindowsCtrlAltChordRepair } from './terminal-windows-ctrl-alt-chord-classification' -function getTerminalUrlOpenHint(): string { - return navigator.userAgent.includes('Mac') - ? '⌘+click to open or ⇧⌘+click for system browser' - : 'Ctrl+click to open or Shift+Ctrl+click for system browser' -} - function defaultLinkTooltipText(uri: string, openLinkHint: string): string { return `${uri} (${openLinkHint})` } @@ -60,7 +54,6 @@ export function createPaneDOM( const fitAddon = new FitAddon() const searchAddon = new SearchAddon() const unicode11Addon = new Unicode11Addon() - const openLinkHint = getTerminalUrlOpenHint() // Why: async tooltip formatting can resolve after hover changes, so stale // results must not overwrite the tooltip for the currently hovered link. let linkTooltipHoverToken = 0 @@ -83,6 +76,7 @@ export function createPaneDOM( if (uri) { linkTooltipHoverToken += 1 const hoverToken = linkTooltipHoverToken + const openLinkHint = options.linkOpenHint() linkTooltip.textContent = defaultLinkTooltipText(uri, openLinkHint) linkTooltip.style.display = '' const formatted = options.formatLinkTooltip?.(uri, openLinkHint) diff --git a/src/renderer/src/lib/pane-manager/pane-manager-types.ts b/src/renderer/src/lib/pane-manager/pane-manager-types.ts index 4629cf54e..1c1c63553 100644 --- a/src/renderer/src/lib/pane-manager/pane-manager-types.ts +++ b/src/renderer/src/lib/pane-manager/pane-manager-types.ts @@ -59,6 +59,10 @@ export type PaneManagerOptions = { terminalOptions?: (paneId: number) => Partial terminalTuiScrollSensitivity?: () => number | undefined onLinkClick?: (event: MouseEvent | undefined, url: string) => void + /** Resolved per hover so link-routing setting changes apply without recreating panes. */ + // Why: required so dropping the wiring is a compile error — an optional hint with a + // default would silently serve stale copy that no test can distinguish. + linkOpenHint: () => string formatLinkTooltip?: ( url: string, openLinkHint: string diff --git a/src/renderer/src/lib/pane-manager/pane-split-close.test.ts b/src/renderer/src/lib/pane-manager/pane-split-close.test.ts index 9ea4aa0eb..48ae877e3 100644 --- a/src/renderer/src/lib/pane-manager/pane-split-close.test.ts +++ b/src/renderer/src/lib/pane-manager/pane-split-close.test.ts @@ -146,7 +146,7 @@ describe('splitManagedPane', () => { panes, root: root as unknown as HTMLElement, styleOptions: {}, - managerOptions: {}, + managerOptions: { linkOpenHint: () => '' }, createPaneInternal: () => { panes.set(newPane.id, newPane) return newPane diff --git a/src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.test.ts b/src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.test.ts index 1ac490933..0937b4da6 100644 --- a/src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.test.ts +++ b/src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.test.ts @@ -54,7 +54,10 @@ describe('applyTerminalGpuAcceleration', () => { it('refits after disabling WebGL so DOM renderer dimensions settle', () => { const pane = createPane() - const options: PaneManagerOptions = { terminalGpuAcceleration: 'auto' } + const options: PaneManagerOptions = { + linkOpenHint: () => '', + terminalGpuAcceleration: 'auto' + } applyTerminalGpuAcceleration([pane], options, 'off') @@ -69,7 +72,10 @@ describe('applyTerminalGpuAcceleration', () => { }) const pane = createPane() pane.hasComplexScriptOutput = true - const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' } + const options: PaneManagerOptions = { + linkOpenHint: () => '', + terminalGpuAcceleration: 'on' + } applyTerminalGpuAcceleration([pane], options, 'auto') @@ -84,7 +90,10 @@ describe('applyTerminalGpuAcceleration', () => { }) const pane = createPane() pane.webglDisabledAfterContextLoss = true - const options: PaneManagerOptions = { terminalGpuAcceleration: 'auto' } + const options: PaneManagerOptions = { + linkOpenHint: () => '', + terminalGpuAcceleration: 'auto' + } applyTerminalGpuAcceleration([pane], options, 'on') @@ -94,7 +103,10 @@ describe('applyTerminalGpuAcceleration', () => { it('keeps context-loss latches when the acceleration mode is unchanged', () => { const pane = createPane() pane.webglDisabledAfterContextLoss = true - const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' } + const options: PaneManagerOptions = { + linkOpenHint: () => '', + terminalGpuAcceleration: 'on' + } applyTerminalGpuAcceleration([pane], options, 'on') @@ -107,7 +119,10 @@ describe('applyTerminalGpuAcceleration', () => { userAgent: 'Mozilla/5.0 (X11; Linux x86_64)' }) const pane = createPane() - const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' } + const options: PaneManagerOptions = { + linkOpenHint: () => '', + terminalGpuAcceleration: 'on' + } applyTerminalGpuAcceleration([pane], options, 'auto') diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 7238c4a0d..541444f6d 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -263,6 +263,7 @@ export function getDefaultSettings(homedir: string): GlobalSettings { openLinksInApp: false, localhostWorktreeLabelsEnabled: false, openLinksInAppPreferencePrompted: false, + openLinksInAppModifierInverts: false, openAgentTabsInChatByDefault: false, experimentalNativeChat: false, nativeChatSessionOptions: {}, diff --git a/src/shared/telemetry-events.ts b/src/shared/telemetry-events.ts index 4428bdc95..007e48cc7 100644 --- a/src/shared/telemetry-events.ts +++ b/src/shared/telemetry-events.ts @@ -242,6 +242,7 @@ type BooleanGlobalSettingsKey = { export const SETTINGS_CHANGED_WHITELIST = [ 'editorAutoSave', 'openLinksInApp', + 'openLinksInAppModifierInverts', 'experimentalMobile', 'experimentalPet', 'experimentalNativeChat', diff --git a/src/shared/types.ts b/src/shared/types.ts index 0aac474ca..dcf432e1a 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -2788,6 +2788,8 @@ export type GlobalSettings = { localhostWorktreeLabelsEnabled?: boolean /** Tracks the one-time first-use prompt for terminal link routing (avoid silently changing where links open). */ openLinksInAppPreferencePrompted: boolean + /** Opt-in: Shift+modifier click inverts openLinksInApp instead of always forcing the system browser. Off keeps the historical one-way escape hatch. */ + openLinksInAppModifierInverts?: boolean /** Opt-in: open new coding-agent tabs in native chat instead of the raw terminal; optional for legacy settings. */ openAgentTabsInChatByDefault?: boolean /** Experimental native chat surface for Claude/Codex sessions; off by default. */