[lexical] Bug Fix: Update selection format and style on programmatic select#8819
Open
1012ayush wants to merge 2 commits into
Open
[lexical] Bug Fix: Update selection format and style on programmatic select#88191012ayush wants to merge 2 commits into
1012ayush wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Jul 9, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
This approach fails existing tests and doesn't add any new tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What is the current behavior that you are modifying?
When moving a selection programmatically (e.g., using
$getRoot().selectStart()), theRangeSelectionobject updates itsanchorandfocusproperties to the new location, but it fails to update theformatandstylecaches. This results in the new selection holding stale formatting data from the previous cursor position.What are the behavior or changes that are being added by this PR?
This PR ensures that programmatic selection updates correctly synchronize the format and style caches:
LexicalElementNode.ts, theselect()method's fallback logic now resetsselection.format = 0andselection.style = ''to clear stale data when a new element is selected.LexicalTextNode.ts, theselect()method now explicitly inherits the target node's formatting by settingselection.format = this.getFormat()andselection.style = this.getStyle().Closes #8817
Test plan
Before
When selecting text with a specific format (e.g., bold) and then triggering a programmatic selection change (like clicking a button that calls
selectStart()),$getSelection().hasFormat('bold')incorrectly remainstruebecause the bitmask is never cleared.After
Programmatic selection changes now correctly flush the format cache. Moving the selection via
selectStart()to an unformatted node correctly returnsfalsefor$getSelection().hasFormat('bold').Note: Verified locally using the reproduction StackBlitz provided in the original issue.