Repository navigation
fix(preview): open links in the default browser instead of navigating the preview - #9
Merged
Merged
Conversation
… the preview The preview WebView had no navigation policy, so link behavior fell through to WebKit defaults: a plain http(s) click replaced the whole preview with the remote page, target=_blank and non-http schemes were handed to the system, and relative links resolved against the app bundle (baseURL) so they always failed. Add a pure LinkPolicy that maps a clicked URL to allow / open externally / open as a Markout document / cancel, re-anchoring bundle-relative file URLs onto the document's own directory, and wire it into PreviewView.decidePolicyFor. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018tFSJJcyAkW3PbRv1WLuYo
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018tFSJJcyAkW3PbRv1WLuYo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Clicking a link in the preview did three different things depending on the link, because
PreviewView.Coordinatorimplemented no navigation policy at all — behaviour fell through to WebKit defaults:https://…target="_blank", ⌘-clickmailto:and other schemes./other.mdBundle.main.resourceURL(the app bundle), so it always failedFix
LinkPolicy(pure, unit-tested) maps a clicked URL to one of four actions:http/https/mailto/ any other scheme →.openExternally→NSWorkspace.shared.open, navigation cancelled, so the preview is never replaced#anchor→.allow, so TOC links still scroll the preview.md/.markdown/.txt… →.openDocument→ opens in a new Markout window.pdf, images) →.openExternally.allowBecause the preview is loaded with
loadHTMLString(baseURL: Bundle.main.resourceURL), a relative href resolves inside the app bundle.LinkPolicydetects file URLs underbaseURLand re-anchors the remaining relative path onto the document's own directory, which is what makes relative links work for the first time.ContentViewnow passesdocumentURLthrough toPreviewView.Tests
10 new tests in
LinkPolicyTests; full suite green (129 tests, 24 suites).Manually verified by launching the app on a document containing an external link, a
mailto:link, a relative.mdlink and an in-page anchor.Version
Bumped to 0.2.0 (
CFBundleVersion1 → 2) — covers everything since v0.1.0: themarkoutCLI, the Find menu, reload-from-disk, and this fix.🤖 Generated with Claude Code
https://claude.ai/code/session_018tFSJJcyAkW3PbRv1WLuYo