Skip to content

fix(terminal): reveal Markdown links at target lines - #9518

Merged
nwparker merged 2 commits into
stablyai:mainfrom
kaynansc:kaynansc/fix-md-file-line
Jul 24, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
kaynansc:kaynansc/fix-md-file-line

Conversation

@kaynansc

@kaynansc kaynansc commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Clicking a terminal file link with a line number (e.g. docs/guide.md:230) now navigates to that exact line instead of opening the Markdown file at the top.

ELI5

When you click a file link in the terminal that points to a specific line, Orca now jumps you straight to that line — even for Markdown files, which previously just opened at the beginning.

Root cause & fix

Terminal links already parsed the :line suffix, but the pending line reveal is consumed by Monaco, and Markdown files opened in Orca's rich (non-Monaco) view — so nothing honored the reveal. The fix, in terminal-file-open-routing.ts, switches Markdown line targets to source mode via setMarkdownViewMode(fileId, 'source') so Monaco mounts and can navigate. It also scopes the reveal to the opened editor tab's fileId (resolved from activeFileIdByWorktree[worktreeId], falling back to filePath) so owner-qualified tabs across local/SSH/runtime contexts get the reveal instead of an ambiguous path key. terminal-file-link-conformance.ts adds a "relative markdown path with line" parser case.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Test file: src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • On branch: 83 passed (83).
  • Reverting the two fix files re-runs to 10 failed / 73 passed — the test captures the bug. Sample assertion: the 2nd setPendingEditorReveal call is missing "fileId": "/tmp/src/second.ts", and the new Markdown test's setMarkdownViewMode(fileId, 'source') is never called.
  • Lint clean: oxlint on both fix files reports no findings.
# on branch
Test Files  1 passed (1) | Tests 83 passed (83)

# fix files reverted to origin/main
Test Files  1 failed (1) | Tests 10 failed | 73 passed (83)

Trade-offs

None — pure fix. Markdown links without a line target, non-Markdown files, and HTML/system-default opens are unchanged.

Regression risk

Zero-regression: only the line-carrying branch of openDetectedFilePath changes, and only Markdown-with-line paths gain the view-mode switch. Non-affected paths remain byte-identical, and the 73 unrelated tests pass on both branch and reverted states. No new filesystem, IPC, or network calls; authorization and stat checks still run unchanged.

Credit to @kaynansc for the original fix. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@kaynansc
kaynansc marked this pull request as ready for review July 20, 2026 05:19
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Terminal file opening now computes the detected language once and, for Markdown line links, resolves the active file ID, switches the Markdown view to source mode, and attaches that ID to the pending editor reveal. Tests add Markdown-aware store mocks and verify file-targeted line navigation. A conformance fixture covers relative Markdown paths with line numbers.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix well, but it omits required template sections like Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Add the missing template sections; include 'No visual change' for Screenshots, a filled Testing checklist, AI Review Report, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change to terminal Markdown line-link handling.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/terminal-pane/terminal-file-open-routing.ts (1)

186-208: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Scope line reveals to the exact editor tab for all file types.

The PR summary mentions scoping line reveals to the actual opened editor tab (which is crucial for owner-qualified tabs, like remote files). However, fileId is currently only extracted and passed to setPendingEditorReveal if language === 'markdown'. For other file types, fileId will be undefined, which may cause line reveals in owner-qualified tabs to break or target the wrong tab if filePath alone isn't unique.

Consider moving the fileId resolution outside the if (language === 'markdown') block so that all line-targeted files benefit from exact tab targeting. Note: this will require updating any existing terminal link tests for non-Markdown files to expect the fileId property in the setPendingEditorReveal mock payload.

🐛 Proposed fix
-    if (line !== null) {
-      let fileId: string | undefined
-      if (language === 'markdown') {
-        const openedStore = useAppStore.getState()
-        fileId = openedStore.activeFileIdByWorktree[worktreeId] ?? filePath
-        // Why: rich Markdown has no line-based reveal consumer; line links must mount Monaco.
-        openedStore.setMarkdownViewMode(fileId, 'source')
-      }
+    if (line !== null) {
+      const openedStore = useAppStore.getState()
+      const fileId = openedStore.activeFileIdByWorktree[worktreeId || ''] ?? filePath
+
+      if (language === 'markdown') {
+        // Why: rich Markdown has no line-based reveal consumer; line links must mount Monaco.
+        openedStore.setMarkdownViewMode(fileId, 'source')
+      }
       const targetColumn = column ?? 1
       store.setPendingEditorReveal(null)
       schedulePendingEditorReveal(() => {
         if (requestId !== latestOpenDetectedFilePathRequestId) {
           return
         }
         store.setPendingEditorReveal({
           filePath,
-          ...(fileId ? { fileId } : {}),
+          fileId,
           line,
           column: targetColumn,
           matchLength: 0
         })
       })
     }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c5262fcf-ac81-47c8-9069-60d67477441f

📥 Commits

Reviewing files that changed from the base of the PR and between a02389c and 61ff8884d59d1075a76335690aed923ec35a4d5e.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-file-open-routing.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • src/shared/terminal-file-link-conformance.ts

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 20, 2026 18:25
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:35
@nwparker
nwparker force-pushed the kaynansc/fix-md-file-line branch from f5b9181 to 1660457 Compare July 23, 2026 11:49
@nwparker
nwparker force-pushed the kaynansc/fix-md-file-line branch from 1660457 to a766324 Compare July 24, 2026 07:37
@nwparker
nwparker merged commit d50ea09 into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much @kaynansc — terminal Markdown line links now navigate Monaco to the exact line. Resolved the conflict with #8215 (WSL links, landed today) preserving both behaviors, 91 tests pass, and merged. 🙏

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(terminal): reveal Markdown links at target lines

* fix(terminal): scope line reveals to opened tabs

---------

Co-authored-by: kaynan <[email protected]>
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.

5 participants