Skip to content

[lexical] Bug Fix: refresh selection format and style on a programmatic move - #8948

Closed
LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:fix/8817-programmatic-selection-format
Closed

LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:fix/8817-programmatic-selection-format

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Moving the selection through the node APIs (selectStart, selectEnd, select, selectPrevious, selectNext) repointed the anchor but left format and style holding the values of the old position, so hasFormat and the style helpers kept reporting the formatting of wherever the selection used to be.

$internalCreateSelection already re-reads format and style from the anchor whenever a DOM-driven selection change lands on a different node, which is why clicking or arrowing keeps a toolbar in sync. The node select() paths never did, so they were the only way to move a selection and keep stale state.

Both TextNode.select and ElementNode.select now run the same refresh, and only when the anchor actually changes node: a format toggled on a collapsed caret is armed for the next insertion rather than backed by the node, so re-selecting the same node must leave it alone. Tests cover both directions for format and style, plus the two armed-in-place controls.

Fixes #8817

…ic move

Moving the selection through the node APIs (selectStart, selectEnd, select,
selectPrevious, selectNext) repointed the anchor but left format and style
holding the values of the old position, so hasFormat and the style helpers
kept reporting the formatting of wherever the selection used to be.

$internalCreateSelection already re-reads format and style from the anchor
whenever a DOM-driven selection change lands on a different node, which is
why clicking or arrowing keeps a toolbar in sync. The node select() paths
never did, so they were the only way to move a selection and keep stale
state.

Both TextNode.select and ElementNode.select now run the same refresh, and
only when the anchor actually changes node: a format toggled on a collapsed
caret is armed for the next insertion rather than backed by the node, so
re-selecting the same node must leave it alone.

Fixes meta#8817
@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 9:34am
lexical-playground Ready Ready Preview Aug 7, 2026 9:34am

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

This branch was successfully deployed

2 active deployments
Preview – lexical — 4d3ff209 Deployed Aug 7, 2026 by vercel[bot]
Preview – lexical-playground — 4d3ff209 Deployed Aug 7, 2026 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: Programmatically moving a Selection does not update the Formatting nor Style

2 participants