Repository navigation
Description
Several open PRs try to let an embedder take over a click that AppKit or the engine currently handles itself:
- Let an embedder disable the https:// prepend for a bare href #165 (
LinkStyle.bareHrefs) and Let an embedder route Markdown URL clicks through their own model #166 (onURLLinkClick) by @paulscan: route[label](href)clicks with non-web targets such as relative paths, opaque ids and custom schemes. - Allow opt-in task toggles in read-only editors #178 (mine): let a read-only note still toggle its checklist.
- Route unhandled Escape and Tab to the embedder #176 (mine) already uses this pattern for Escape/Tab.
Rather than one configuration flag per case, I'd like to propose a single pattern and ask whether it fits your plans before anyone writes more code for it.
The pattern
The engine reports an activation with source coordinates and the host returns whether it handled it. If there is no host callback, or the host returns false, today's behavior is unchanged.
public struct MarkdownLinkActivation: Sendable, Equatable {
public enum Kind: Sendable, Equatable { case inlineLink, wikiLink, autolink }
public let kind: Kind
public let destination: String // as written in the source: no https:// prefix, no <>, no title, no decoding
public let sourceRange: NSRange // the whole link token, in raw Markdown coordinates
public let modifierFlags: NSEvent.ModifierFlags
public let isEditable: Bool
}
public var onLinkActivation: ((MarkdownLinkActivation) -> Bool)?- It is called before any default handling, both in
textView(_:clickedOnLink:at:)and in the dropped-click fallback. true: no browser, noonLinkClick, and the pre-click caret is restored as for wiki links.falseornil: the existing wiki-link or URL route, including thehttps://prefix, is unchanged.- A destination
URL(string:)can't parse, such as<../a b.md>, is still clickable, so the host can route it.
A task-checkbox counterpart would follow the same shape: sourceRange, lineRange, isChecked and isEditable, where true means no text mutation and no undo entry. That makes a read-only flag like #178 unnecessary: the host decides per click.
Why one seam
- Smaller public surface. Two callbacks replace Let an embedder disable the https:// prepend for a bare href #165, Let an embedder route Markdown URL clicks through their own model #166 and Allow opt-in task toggles in read-only editors #178, and the pattern matches what Route unhandled Escape and Tab to the embedder #176 already does for keys.
- The engine stays policy-free. It doesn't guess which targets are web URLs; the host knows its own model.
- No behavior change for existing embedders.
I have onLinkActivation implemented and tested (link kinds, true/false/nil, editable/read-only, the dropped-click path, unparsable destinations) in my fork and can open it as a draft PR against main. If you'd rather implement this yourself, or shape it differently, that's completely fine. What matters to me is that the capability exists upstream.
cc @paulscan, since this would cover #165/#166; I'd value your view on whether it fits your use case.
Activity
yvos commentedon Sep 27, 2026
Draft implementation of the link half: #192
paulscan commentedon Sep 27, 2026
Yep, this covers my use case, and I prefer it to #165 and #166, so I'm closing those in favor of #192. My one request on destination parsing is in a review comment on #166 (comment)