Skip to content

Proposal: one "host decides" seam for link and checkbox activation #190

Open

Description

@yvos

Several open PRs try to let an embedder take over a click that AppKit or the engine currently handles itself:

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, no onLinkClick, and the pre-click caret is restored as for wiki links.
  • false or nil: the existing wiki-link or URL route, including the https:// 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

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

  1. yvos commented on Sep 27, 2026

    @yvos
    ContributorAuthor

    Draft implementation of the link half: #192

  2. paulscan commented on Sep 27, 2026

    @paulscan

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions