Skip to content

fix(terminal): activate fresh OSC links on first click - #11453

Merged
nwparker merged 1 commit into
mainfrom
nwparker/sel-links
Jul 30, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/sel-links

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

Fresh OSC 8 links printed under a stationary pointer now activate on the first modifier-click:

  • Cmd-click on macOS, or Ctrl-click on Linux/Windows, opens the link in Orca.
  • Cmd/Ctrl+Shift-click preserves system-browser routing.
  • PTY mouse reporting remains suppressed for the link gesture.

xterm snapshots its current link on mousedown, but normally resolves a newly painted link only after mousemove. A guarded capture-phase listener now primes the linkifier before xterm takes that snapshot. If xterm internals change or are unavailable, the behavior safely falls back to normal hover activation.

Screenshots

Fresh Claude Code OSC 8 links before interaction:

Fresh Claude OSC 8 table

The first trusted Cmd-click, without a preceding mousemove, opened exactly one in-app #11323 tab:

First Cmd-click opened the link in Orca

The first trusted Cmd+Shift-click resolved #11326 and followed system-browser routing:

First Cmd+Shift-click resolved system-browser routing

Electron/Playwright reproduction used trusted mouse events. Before this change, a fresh Meta-click with no mousemove did not open the link. After this change, the first Meta-click opened one in-app tab, and the first Meta+Shift-click took the system-browser route while preserving PTY mouse handling. The run reported zero console errors.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Also passed:

  • pnpm run build:electron-vite
  • 141 focused terminal-link tests
  • Electron/Playwright trusted-event E2E for first-click in-app and system-browser routing

AI Review Report

AI review found no remaining correctness or maintainability issues. It checked capture-listener ordering, PTY suppression, listener disposal on pane close and lifecycle unmount, established hover state, and safe degradation if xterm internals change.

The cross-platform audit verified Meta on macOS and Ctrl on Linux/Windows, retained macOS Ctrl-click context-menu behavior, preserved Shift routing, and found no path, shell, or Electron platform differences introduced by this renderer-local change. SSH and folder workspaces are unaffected.

Security Audit

No new IPC, authentication, secret handling, command execution, path handling, dependency, or external input surface was introduced. The new internal access is guarded by shape checks and a fail-safe catch; failure returns to normal hover behavior. No follow-up security work is needed.

Notes

The visual evidence was uploaded through GitHub user attachments and is not part of the repository diff.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d1b813a-9727-41a4-8f82-e55a4fec187d

📥 Commits

Reviewing files that changed from the base of the PR and between f4e4638 and b34517e.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/terminal-linkifier-click-priming.test.ts
  • src/renderer/src/components/terminal-pane/terminal-linkifier-click-priming.ts
  • src/renderer/src/components/terminal-pane/terminal-url-link-click.test.ts
  • src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

linkifier._activeLine = -1
}
}
linkifier._handleMouseMove(event)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Mousedown event passed to _handleMouseMove may silently no-op in future xterm builds

_handleMouseMove is designed for mousemove events. If a future xterm build guards on event.type === 'mousemove' (or an equivalent internal check), the function would return early without setting _currentLink, and the try/catch would not surface it — priming would silently stop working. The existing catch block handles thrown errors, but a silent early-return from a type guard would degrade the feature invisibly. A test assertion like expect(linkifier._currentLink).toBeDefined() after calling the handler in the E2E suite would catch this regression.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes OSC 8 links not activating on first modifier-click when no mousemove event has occurred since the link was painted. xterm.js snapshots its active link state on mousedown but only resolves new links on mousemove, so a fresh link under a stationary pointer was invisible to the first click.

  • Adds terminal-linkifier-click-priming.ts: a capture-phase mousedown listener that calls xterm's internal _handleMouseMove with the click event before xterm takes its snapshot, forcing link resolution in place. For fresh links (no _currentLink) it also clears _lastBufferCell/_activeLine so xterm skips its position-cache shortcut. All internal access is guarded by shape checks and a try/catch.
  • Extends PTY mouse suppression in installHttpLinkClickFallback to also fire when isTerminalLinkifierHoverActive is true, ensuring a primed OSC link suppresses PTY reporting just as a hover-established link would.
  • Wires the new disposable into use-terminal-pane-lifecycle.ts following the existing per-pane disposal pattern, with proper cleanup on pane close and lifecycle unmount.

Confidence Score: 4/5

Safe to merge. The change is renderer-local, introduces no new IPC surfaces, and degrades gracefully if xterm internals are unavailable.

The core mechanism — calling xterm's private _handleMouseMove with a mousedown event — works correctly today and is tested end-to-end, but silently relies on xterm not type-checking event.type internally. A future xterm update that guards on event.type would cause priming to stop working without throwing, which the existing catch block would not detect. The lifecycle wiring and PTY suppression changes are straightforward and low-risk.

Files Needing Attention: terminal-linkifier-click-priming.ts is worth revisiting whenever xterm is upgraded, since it relies on internal fields that carry no public stability guarantee.

Important Files Changed

Filename Overview
src/renderer/src/components/terminal-pane/terminal-linkifier-click-priming.ts New module; well-guarded access to xterm internals with try/catch. Minor fragility: _handleMouseMove is called with a mousedown event object, which may behave differently than a mousemove in future xterm builds if type-checks are added internally.
src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts Adds isTerminalLinkifierHoverActive short-circuit in PTY suppression callback, correctly broadening suppression to cover primed OSC links. Gated by isTerminalHttpLinkActivation upstream so plain clicks are unaffected.
src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts Wires new linkifierClickPrimingDisposablesRef into the pane lifecycle, following the exact same install/cleanup pattern as adjacent disposables. Disposal is symmetric on per-pane close and full lifecycle teardown.
src/renderer/src/components/terminal-pane/terminal-linkifier-click-priming.test.ts Comprehensive tests covering priming, hover-state preservation, non-Mac Ctrl path, missing internals (safe degradation), and dispose. Correctly verifies capture listener ordering via options.capture === true check.
src/renderer/src/components/terminal-pane/terminal-url-link-click.test.ts New test verifies PTY suppression fires when _currentLink is set by priming. Uses existing mouseEventForRow fixture (metaKey+shiftKey) which correctly satisfies isTerminalHttpLinkActivation.

Sequence Diagram

sequenceDiagram
    participant User
    participant DOM as DOM (capture phase)
    participant Priming as LinkifierClickPriming
    participant PtySup as PtyMouseSuppression
    participant Linkifier as xterm Linkifier
    participant XtermCore as xterm (bubble phase)

    User->>DOM: modifier+mousedown
    DOM->>Priming: handleMouseDown (capture, registered 1st)
    Priming->>Priming: isTerminalLinkActivation?
    alt fresh link (_currentLink absent)
        Priming->>Linkifier: clear _lastBufferCell, _activeLine
        Priming->>Linkifier: _handleMouseMove(event)
        Linkifier->>Linkifier: resolve OSC 8 at position → set _currentLink
    else established hover (_currentLink present)
        Priming->>Linkifier: _handleMouseMove(event) [no state clear]
    end
    DOM->>PtySup: handleMouseDown (capture, registered 2nd)
    PtySup->>Linkifier: isTerminalLinkifierHoverActive?
    Linkifier-->>PtySup: true (_currentLink set)
    PtySup->>XtermCore: "mouseEventsRequireAlt = true"
    DOM->>XtermCore: mousedown (bubble phase)
    XtermCore->>Linkifier: read _currentLink snapshot
    Linkifier-->>XtermCore: link URL
    XtermCore->>User: open link (in-app or system browser)
Loading

Reviews (1): Last reviewed commit: "fix(terminal): activate fresh OSC links ..." | Re-trigger Greptile

@nwparker
nwparker merged commit eb58e00 into main Jul 30, 2026
45 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant