Skip to content

[Breaking Change][lexical][lexical-link] Bug Fix: Collapse through inline elements in deleteCharacter - #7180

Merged
ivailop7 merged 2 commits into
meta:mainfrom
etrepum:collapse-inline-element
Feb 15, 2025
Merged

ivailop7 merged 2 commits into
meta:mainfrom
etrepum:collapse-inline-element

Conversation

@etrepum

@etrepum etrepum commented Feb 14, 2025 •

Copy link
Copy Markdown
Collaborator

Breaking Change

ElementNode.collapseAtStart(range) would previously only be called on the direct parent of the anchor's node, so the presence of anything like a LinkNode would prevent a ListItemNode from collapsing. Now it will also be called on parents under certain conditions.

Description

Previously the collapse algorithm looked only at the direct parent of the anchor. If the anchor is inside an inline node (e.g. a TextNode in a LinkNode) then the expected behavior will not happen (such as a LinkItemNode being replaced with a ParagraphNode).

Now the algorithm works like this:

  • Start with the anchor node (if its offset is 0) and then all of its parents:
    • If the current node is an ElementNode
      • If node.collapseAtStart(range) returns true, stop
      • If node.isInline() returns false, stop
    • If the node is not the first child of its parent, stop

Closes #7150

Test plan

e2e tests for new behavior

Before

Pressing delete at the beginning of a ListItemNode would not collapse the node if the anchor was inside of an inline element (such as a LinkNode)

After

Pressing delete at the beginning of a ListItemNode collapses through inline element node(s) as expected

@vercel

vercel Bot commented Feb 14, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2025 5:51am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2025 5:51am

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 14, 2025
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Feb 14, 2025

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — d11b736c Deployed Feb 15, 2025 by vercel[bot]
Preview – lexical — d11b736c Deployed Feb 15, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Can't delete first list item with link

3 participants