Repository navigation
fix(editor): end links where their text ends - #40
Merged
Merged
Conversation
Pasting a URL left the caret at the link's right edge, and everything typed from there joined the link while its href stayed the URL. Tiptap makes the link mark inclusive whenever autolink is on, so the same happened after a doc link, an edited date, an HTML paste, a click at a link's end, and at the start of a paragraph opening with a link. KnotLink is now non-inclusive (as prosemirror-schema-basic's link is). Tiptap's own fix (tiptap#8335, 3.31.4) only covers a typed space. Follow-ups the change needs or exposed: - Pasting a URL over a selection collapses the caret to the link end, so the next keystroke no longer replaces the new link. - The toolbar's Link button shows the link Apply/Remove act on, also at a link's edges; an empty Apply no longer silently unlinks it. - Toolbar Apply with nothing selected inserts the URL as linked text instead of relying on a stored (now one-character) mark. - The `//` date picker no longer opens after a URL scheme; it took keyboard focus right after pasting https://host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Pasting a link left the cursor at the link's right edge, and everything typed afterwards became part of the link. The href stayed the original URL, so the page and the Markdown export ended up with
[https://example.com and more](https://example.com).Root cause
@tiptap/extension-linksetsinclusive() { return this.options.autolink }, and knot turns autolink on. ProseMirror carries an inclusive mark onto text typed at its right edge. Paste made this the common case, because the core paste rule deliberately keeps the caret inside a link that ends the pasted text (tiptap#7692). The same thing happened in other places:Upstream's fix (tiptap#8335, 3.31.4) only stops a typed space from joining the link. Punctuation, or text typed without a space, still joined.
Fix
KnotLinkis non-inclusive (extensions.ts). This matches prosemirror-schema-basic's link.inclusiveis a local editing rule and is never serialised, so the Y.Doc,tools/schema.jsonand the server are unchanged, and no migration is needed.excludesis untouched, so y-tiptap still writes thelinkkey thatto_markdownreads.Selection.near, so select-all and table-cell selections stay valid.setLink, soisAllowedUristill rejectsjavascript:.//date picker no longer opens after a URL scheme (https://,file:///). It took keyboard focus right after pastinghttps://host, so the next keystrokes went into the picker instead of the page.Intended behaviour changes
exitableArrowRight handler is now inert. Before, at the end of a paragraph it wrote a stray space into the shared doc.Tests
linkBoundary.test.tscovers paste and typing at link edges, the date picker after URL schemes (with a positive control), and select-all paste.toolbarLink.test.tscovers the helpers.EditorToolbar.link.test.tsxcovers the toolbar wiring.src/test/editorInput.ts.vitest: 405/405 pass.tscandeslintare clean. e2e was not run: no spec types after a link, uses the toolbar link flow or touches the date picker.Not in this PR
knot://is not a registered link protocol, sosetLinkwith aknot://doc/…href over a selection does nothing.🤖 Generated with Claude Code