Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
This looks good to me. Thanks for the careful fix and the clear before/after tests. $wrapSelectionInMarkNode now skips a partly selected inline element and lets the text case wrap its selected children, so a comment that enters a link from before behaves like one that starts inside it. The four new tests fail without the change and pass with it.
A few optional, non-blocking suggestions:
- Playground link colour under a comment (
packages/lexical-playground/src/themes/PlaygroundEditorTheme.css:639-643). Now that the mark sits inside the<a>, the marked part of a link (for exampleLexiinLexical website) renders black..PlaygroundEditorTheme__marksets nocolor, so the browser's defaultmarkcolour applies.mainalready does this for a comment that starts inside a link (point 1 of #3266), so leaving it for that follow-up is fine; addingcolor: inheritto the rule would fix it in the playground if you want it here. - Pin the AutoLink trade-off with a test. The description explains that the auto-link extension unlinks a partly marked
AutoLinkNodeuntil the mark is removed. A small unit test withAutoLinkExtensionandMarkExtensionassertingbef,mark[ore ],mark[htt],p://a.dev after, and the autolink back after$unwrapMarkNode, would keep that behaviour visible for the #3266 work. - Test plan output. AGENTS.md (Commits and Pull Requests) asks for the real command output under
### After. Your Before section pastes it, but After describes the results ("18 passed", "all 9,580 tests pass"); pasting the output there would match the template.
…the whole link $wrapSelectionInMarkNode wrapped any inline element in the selection whole, so commenting on part of a link marked the entire link. Wrap an inline element whole only when both its first and last descendants are selected; otherwise wrap its selected children inside it. Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
a2193e6 to
af60d58
Compare
|
Thanks for the review. I rebased onto — Ved Thakar |
There was a problem hiding this comment.
Thanks, this looks good. Marking a partly selected inline element's selected children, instead of wrapping the element itself, fixes #5606 in the right place. The four new tests fail on main and pass with the change. Everything below is optional and non-blocking.
- Add a
Verify:paragraph to the changeset (.changeset/mark-partial-link.md:5). The fix changes observable output, and CONTRIBUTING.md ("Changesets", theVerify:bullet) and.changeset/README.md("Behavior changes") ask for aVerify:paragraph in that case. For example:Verify: marks created over a selection that starts before a link and ends inside it. The part inside the link is now a separate mark nested in the link, so a custom
createNoderuns once more, and an autolink covered this way is unlinked until the mark is removed. - Autolinks (
packages/lexical-mark/src/index.ts:105-112). As the description notes, anAutoLinkNodeentered from before is now skipped here, andAutoLinkExtension'shandleLinkEditunlinks it while the mark exists. It relinks once the mark is unwrapped. That matchesmainfor selections that start inside an autolink. If maintainers would rather keep autolinks intact until #3266, wrapping a partly selectedAutoLinkNodewhole would keep the old behaviour for that one node type. - Caret after a backward wrap (
packages/lexical-mark/src/index.ts:156-161). WithisBackward, the helper callsselectStart()on the last mark it created. For a backward selection from inside a link to before it, that is now the mark inside the link, so the caret lands at the start oflirather than at the start of the commented range. Remembering the first created mark for the backward case would fix it. - Extra test cases. Two would be worth pinning: a selection that ends at offset 0 of the link's text or at the element point
(link, 0), where nothing of the link is selected andmainalso wrapped the whole link; and the autolink outcome above. - Playground styling, possibly as a follow-up. A mark inside a link takes the browser's default
marktext colour, so the commented part of a link turns black in the playground.mainalready does this for selections that start inside a link. Adding.PlaygroundEditorTheme__link .PlaygroundEditorTheme__mark { color: inherit; }topackages/lexical-playground/src/themes/PlaygroundEditorTheme.csswould fix it. This is the first point of #3266, which the description scopes out.
A small process note: AGENTS.md ("Commits and Pull Requests") asks the test plan's ### After section to carry the pasted output of the command, not a summary of it.
| '@lexical/mark': patch | ||
| --- | ||
|
|
||
| [fix] `$wrapSelectionInMarkNode` marks only the selected part of a link when the selection starts before the link and ends inside it, instead of the whole link |
There was a problem hiding this comment.
Optional: this fix changes observable output, so CONTRIBUTING.md ("Changesets", the Verify: bullet) and .changeset/README.md ("Behavior changes") ask for a Verify: paragraph, for example:
Verify: marks created over a selection that starts before a link and ends inside it. The part inside the link is now a separate mark nested in the link, so a custom `createNode` runs once more, and an autolink covered this way is unlinked until the mark is removed.| } else if ( | ||
| $isElementNode(node) && | ||
| node.isInline() && | ||
| !$isFullySelected(node, selectedKeys) | ||
| ) { | ||
| // Case 3: a partly selected inline element node (eg. a link) is not | ||
| // wrapped whole. Its selected children are wrapped instead, inside it. | ||
| continue; |
There was a problem hiding this comment.
Optional, non-blocking: an AutoLinkNode that a selection enters from before is now skipped here, and AutoLinkExtension's handleLinkEdit then unlinks it while the mark exists, relinking it once the mark is removed. main already does this for selections that start inside an autolink, so this is consistent. If maintainers prefer to keep autolinks intact until #3266, treating a partly selected AutoLinkNode as case 4 (wrap it whole) would preserve the old behaviour for that one node type.
Description
This solves issue #5606: adding a comment over part of a link marks the whole link.
Current behavior.
$wrapSelectionInMarkNode(which the playground's CommentPlugin uses) has a case that adds any inline element node in the selection to the mark whole. When a selection starts before a link and ends inside it,extract()returns theLinkNodeitself as well as its selected text, so the whole link goes into the mark. Withbefore link after, selectingore ligivesbef<mark>ore <a>link</a></mark> afterinstead of marking onlyli. A selection that starts inside the link never hits this case, so only selections entering a link from before it were wrong.What this changes. An inline
ElementNodeis wrapped whole only when it is fully selected.extract()splits text at the selection boundaries, so that's the case when its first and last descendants are both in the extracted nodes (or it has none). A partly selected inline element is skipped, the same way a mark is, and its selected children are wrapped by the text case, inside it:bef<mark>ore </mark><a><mark>li</mark>nk</a> after.A
LinkNodestays one node, and its unselected part stays unmarked.A fully selected link, or an empty inline element, is still wrapped whole as before.
Decorators and block elements are unchanged.
Autolinks. An
AutoLinkNodewith a mark inside it is still unlinked by the auto-link extension (handleLinkEdit). This already happens onmainfor a selection that starts inside an autolink, and it affects only autolinks. I checked withAutoLinkExtensiononbefore http://a.dev after:ore httgivesbef,mark[ore ],mark[htt],p://a.dev afterwith this change. Onmainit gavebef,mark[ore ,autolink[http://a.dev]], after, with the whole autolink marked.tp:givesbefore ht,mark[tp:],//a.dev afterboth with this change and onmain.Keeping autolinks intact under a mark is Bug: Overlapping Mark Nodes and Link Nodes #3266-type work and is left out of this PR.
This is also point 2 of #3266 ("wrapping half of the linked word with a mark node will wrap the entire link"). Points 1 and 3 there (link styling under a mark, and creating a link over a mark) are separate, so this PR doesn't close #3266.
Closes #5606
Test plan
New tests in
packages/lexical-mark/__tests__/unit/LexicalMarkNode.test.tsonbefore link after, rendering the paragraph as eg.bef,mark[ore ],link[mark[li],nk], after:li+ boldnk, and the selection ends insidenk.The existing
$wrapSelectionInMarkNodetests (inline element and decorator nodes, block elements) pass unchanged.Before
On
mainwith the tests applied and the source change reverted:After
On current
main:LexicalMarkNode.test.ts: 18 passed (the 4 new behaviour tests fail onmain).pnpm run test-unit: all 9,580 tests passtsc,pnpm run flow(0 errors), and eslint/prettier on the changed files: cleanAuthor: Ved Thakar (@Vedthakar)
🤖 Generated with Claude Code