fix(desktop): scroll terminal file links to their line and column
What & why
Cmd-clicking a terminal link such as apps/desktop/src/main/index.ts:240:7 opened the built-in file viewer at line 1 because pane navigation discarded the detected line and column.
Carry the position through file navigation and reveal it once the editor is ready. Location requests work for new panes, new tabs, and existing panes, including repeated clicks on the same line. They select the source view, take precedence over cached scroll position, and are cleared after use so ordinary file opens retain their existing behavior. If the user leaves the pane while a file loads, defer the jump until that pane is active again so loading cannot steal focus.
How I tested it
bun run lint— passed.bun run typecheck— passed, 42 tasks.- Focused file-navigation, scroll-cache, editor-position, and pending-navigation tests — 17 passed. Covers empty files, out-of-range positions, unfolding the target, deferred focus, latest-request wins, and consumed requests.
- Real Electron CDP verification against this worktree's renderer (
localhost:7405, CDP9245), using terminal input, Cmd-clicks, mouse-wheel scrolling, and pane close/reopen. Captured before/after screenshots, a 70-second recording, and numeric measurements locally.
| CDP interaction | Result |
|---|---|
Original link handler: click :240:7 | Reproduced the bug: line 1, scrollTop 0 |
Fixed handler: click :240:7 | Line 240, column 7; target visible |
Click :400:3 in the existing pane | Line 400, column 3; target visible |
Scroll away, then click :400:3 again | Returns to line 400, column 3 |
Close the pane and reopen with :240:7 | Line 240, column 7 overrides the cached position |
| Delay file response by 5 seconds, click a link, then focus the terminal | Before follow-up: editor steals focus. After: terminal retains focus when loading finishes |
| Return to the loaded file pane | Pending line 240, column 7 is revealed |
| Click line 240 then line 400 while loading is delayed | Only the latest location, line 400, column 3, is applied |
No console errors were captured during the fixed flow; no pending position requests remained afterward. The baseline handler was restored only for reproduction and the fix reinstated before the passing run.
bun run test was also attempted: the desktop suite finished with 4,007 passing and 34 failing tests in unchanged shell/Git integration areas (including worktree import, worktree hooks, and shell-environment tests). The full repository test command therefore does not pass locally.
Checklist
- PR title follows conventional commits (
type(scope): subject) -
bun run lintandbun run typecheckpass (CI fails on lint warnings too) - "Allow edits from maintainers" is checked on fork PRs — not applicable; same-repository branch
Summary by cubic
Fixes terminal file links so Cmd-clicking a path:line:column link (for example, apps/desktop/src/main/index.ts:240:7) opens the editor at that exact position instead of line 1.
- Carries the requested position through file navigation for new panes, new tabs, and existing panes, including repeated clicks on the same line.
- The reveal waits until the editor is ready and the pane is active, so files loading in the background don't steal focus; invalid line and column values are normalized.
- The position takes precedence over the cached scroll position, is cleared after reveal, and always selects the code view and resets any forced view on an existing pane.
Summary by CodeRabbit
-
New Features
- Terminal file links can now open documents directly at the referenced line and column.
- Existing file tabs reuse the requested location, while new tabs remain supported.
- Editors reveal requested positions when the relevant pane is active and preserve normal scroll restoration otherwise.
-
Bug Fixes
- Invalid line and column values are normalized before opening files.
-
Tests
- Added coverage for position handling, tab reuse, navigation, and invalid locations.