[lexical] Bug Fix: update block cursor if selection has changed #7947
+4
−1
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.
In some cases, the selection is created based on the DOM selection (
$internalCreateSelection→$internalCreateRangeSelection→$internalResolveSelectionPoints), and it doesn't match the editor state. This selection isn't marked as dirty (since it's already in sync with the DOM). The issue is that it skips the block cursor update, causing the editor to keep the fake cursor in the wrong position.You can reproduce this issue in the playground using a collapsible block that contains a YouTube node. After selecting the YouTube node, moving the selection with the down arrow key creates a block cursor initially but fails to reset it back to a regular caret.
Another potential fix location:
When creating the DOM-based selection, we could compare it to the existing one and mark it as dirty if it differs. However, since this happens in
$beginUpdate, and with batched updates it might run multiple times per commit, running the comparison during the commit phase might be slightly better.Test plan
Before
Changed hidden caret-color from transparent to red for a demo purpose (block cursor remains visible, real caret is still red):
CleanShot.2025-10-26.at.11.16.14.mp4
After
Now red caret turns back to black, and block cursor disappears:
CleanShot.2025-10-26.at.11.15.47.mp4