fix(core): link lookups at the edges of a link - #3058
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe change updates link boundary detection in ChangesLink boundary handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. A rabbit reads each line, Comment |
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
@blocknote/xl-typst-exporter
commit: |
|
|
@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
left a comment
There was a problem hiding this comment.
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.
…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.
5d04242 to
94ed695
Compare
Two link lookups in
StyleManagerdisagreed about what happens at the edges of a link, because the link mark is non-inclusive.Edit and delete (
editLink,deleteLink→getLinkMarkAtPos): 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'sgetMarkRange, which looks at the node after the position and then the one before, so the link is found at both ends; the+ 1nudge 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) andStyleManager.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
+ 1ingetSelectedLinkUrlthat this replaces.Summary by CodeRabbit