Skip to content

fix(core): link lookups at the edges of a link - #3058

Draft
YousefED wants to merge 1 commit into
mainfrom
fix/link-mark-edges
Draft

fix(core): link lookups at the edges of a link#3058
YousefED wants to merge 1 commit into
mainfrom
fix/link-mark-edges

Conversation

@YousefED

@YousefED YousefED commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Two link lookups in StyleManager disagreed about what happens at the edges of a link, because the link mark is non-inclusive.

Edit and delete (editLink, deleteLinkgetLinkMarkAtPos): the position comes from the link toolbar and can sit at either edge of the link (caret at the end of a link is normal). The lookup now uses tiptap's getMarkRange, which looks at the node after the position and then the one before, so the link is found at both ends; the + 1 nudge the callers used, which only covered the left edge, is gone.

Pre-filling the link form (getSelectedLinkUrl): this answers "is the selected text a link?", so it deliberately reads only the node the selection starts in. Looking on both sides would pre-fill the previous link's URL when a selection starts right after a link. The bug it fixes: selecting only the last character of a link, or a one-character link, read as "no link" and opened the form empty.

Tests: StyleManager.test.ts (headless, the selection lookup at every edge; two cases fail on the old lookup) and StyleManager.browser.test.ts (mounted editor; editing a link with only its last character selected used to split the link).

Extracted from the mobile stack so it can be reviewed on its own; the stack currently carries a + 1 in getSelectedLinkUrl that this replaces.

…l only from the selected text

The link mark is not inclusive, so a mark lookup at either edge of a link
misses it, and editLink / deleteLink compensated with a +1 that covers the
left edge only. getLinkMarkAtPos now uses tiptap's getMarkRange, which
looks after and then before the position, and reads the mark off the node
the range starts with; the callers drop the +1.

getSelectedLinkUrl, which decides whether the link form opens pre-filled,
deliberately reads only the node the selection starts in: a selection that
starts right after a link must not pre-fill that link's URL, while selecting
only the last character of a link, or a one-character link, must.

Tests: headless cases for the selection lookup at every edge, and a mounted
case where editing a link with only its last character selected used to
split it.
@YousefED
YousefED requested a review from nperez0111 September 7, 2026 10:26
@vercel

vercel Bot commented Sep 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
blocknote Ready Ready Preview Sep 7, 2026 10:27am UTC
blocknote-website Ready Ready Preview Sep 7, 2026 10:27am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@3058

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@3058

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@3058

@blocknote/diagram-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/diagram-block@3058

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@3058

@blocknote/math-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/math-block@3058

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@3058

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@3058

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@3058

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@3058

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@3058

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@3058

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@3058

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@3058

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@3058

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-typst-exporter@3058

commit: 038e2f9

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-3058/

Built to branch gh-pages at 2026-09-07 10:35 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@YousefED

YousefED commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@nperez0111 this was claude generated, not directly related to what I was working on, so might be worth a look at any time. I didn't really review this atm

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.

1 participant