[lexical-utils] Bug Fix: Pass editor context to editorState.read() in markSelection#8411
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
|
A simpler fix would be to make |
… markSelection PR #8353 renamed rangeTargetFromPoint to $rangeTargetFromPoint, which now requires an active editor context via $getEditor(). However, the editorState.read() call in markSelection's compute() was not updated to pass {editor}, causing $getEditor() to return null and throw when the selection's anchor/focus is on an element node.
Adds tests covering both text-type and element-type selection points.
The element-type test verifies the fix for the missing {editor} context
in editorState.read(), which caused $getEditor() to throw.
d7eadde to
2739770
Compare
…tead of using $getEditor()
Simpler fix per review feedback: thread the editor argument through
$rangeTargetFromPoint since it's already available in $rangeFromPoints,
removing the need for $getEditor() and the {editor} option on
editorState.read().
Contributor
Author
good point, thankyou! simplified it accordingly |
zurfyx
approved these changes
Apr 28, 2026
Merged
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.
Summary
rangeTargetFromPointto$rangeTargetFromPoint, which now calls$getEditor()to use the extensible DOM API. However, theeditorState.read()call inmarkSelection'scompute()function was not updated to pass{editor}, so$getEditor()returnsnulland throws when the selection's anchor/focus is on an element node (not text).editorreference toeditorState.read(() => { ... }, {editor})so that$getEditor()can find the active editor inside$rangeTargetFromPoint.Test plan
pnpm run test-unit
all test pass, including
✓ unit packages/lexical-utils/src/tests/unit/markSelection.test.tsx (4 tests) 193ms