Skip to content

[lexical] Bug Fix: refresh pending format and style when removeText moves the caret to another node - #8954

Closed
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/6781-remove-text-pending-format
Closed

[lexical] Bug Fix: refresh pending format and style when removeText moves the caret to another node#8954
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/6781-remove-text-pending-format

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Backspacing away an empty paragraph merges the caret into the end of the previous block, but RangeSelection.removeText() only moved the anchor and focus. The pending format/style still described the paragraph that was just deleted, so the next keystroke was inserted with the wrong formatting and split off into its own text node.

removeText() now re-derives format and style from the anchor when the caret ends up in a different node than it started in — getFormat/getStyle for a TextNode, getTextFormat/getTextStyle for an ElementNode. This is the same rule $internalCreateRangeSelection applies when a selection change resolves to a new anchor. When the caret stays put the pending format is left alone, so a format chosen for the next keystroke still survives an ordinary backspace. insertText already snapshots and restores these values around its own removeText() call, so that path is unchanged.

Adds a unit test covering the reported case and a control for the same-node case.

Fixes #6781

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 7, 2026 10:42am
lexical-playground Ready Ready Preview Aug 7, 2026 10:42am

Request Review

@meta-cla meta-cla 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 Aug 7, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Aug 7, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9058 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
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: Removing an empty paragraph with a sibling does not correctly set styles on selection

2 participants