Skip to content

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

Merged
nperez0111 merged 3 commits into
mainfrom
fix/link-mark-edges
Sep 15, 2026
Merged

nperez0111 merged 3 commits 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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved link selection handling when editing links, including selections at link boundaries and document endpoints.
    • Prevented link edits from unintentionally splitting link text.
    • Fixed link deletion so it removes link formatting while preserving the text.
    • Corrected link URL detection to avoid applying a preceding link’s URL when the cursor is immediately after it.
  • Tests
    • Added coverage for link editing, deletion, URL detection, and boundary selections.

@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 15, 2026 9:53am UTC
blocknote-website Ready Ready Preview Sep 15, 2026 9:53am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 28e64a8e-ae78-426d-85b2-0c867f9d3d6e

📥 Commits

Reviewing files that changed from the base of the PR and between 0042d19 and 94ed695.

📒 Files selected for processing (3)
  • packages/core/src/editor/managers/StyleManager.browser.test.ts
  • packages/core/src/editor/managers/StyleManager.test.ts
  • packages/core/src/editor/managers/StyleManager.ts

📝 Walkthrough

Walkthrough

The change updates link boundary detection in StyleManager. URL lookup, link editing, and link deletion now handle boundary positions directly. Unit and browser tests cover selections inside links, at link ends, outside links, and at the document end.

Changes

Link boundary handling

Layer / File(s) Summary
Link lookup semantics
packages/core/src/editor/managers/StyleManager.ts, packages/core/src/editor/managers/StyleManager.test.ts
getLinkMarkAtPos detects marks at both link boundaries. getSelectedLinkUrl reads from the selection start. Tests cover link and non-link positions.
Link editing behavior
packages/core/src/editor/managers/StyleManager.ts, packages/core/src/editor/managers/StyleManager.browser.test.ts
editLink and deleteLink use the supplied position without an offset. Browser tests cover partial selections, link-end selections, unlinking, and document-end positions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: nperez0111

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/link-mark-edges

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

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

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/@blocknote/ariakit@3058

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 94ed695

@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-15 10:12 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

@nperez0111 nperez0111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally that this covers #3081 / #3073: editing at the end replaces the whole link, deleting at the end preserves the text and removes the link, and calls at doc.content.size do not throw. getMarkRange also handles one-character links, which #3081 still misses.

Added focused regression tests reusing the existing fixture. All 8 cases pass in Chromium, Firefox, and WebKit in Docker (24 checks); the 7 existing lookup unit tests and lint also pass. Positions outside the document remain outside this fix’s scope.

YousefED and others added 3 commits September 15, 2026 11:50
…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.
@nperez0111
nperez0111 marked this pull request as ready for review September 15, 2026 10:01
@nperez0111
nperez0111 merged commit 476bea5 into main Sep 15, 2026
17 of 18 checks passed
@nperez0111
nperez0111 deleted the fix/link-mark-edges branch September 15, 2026 10:01
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.

2 participants