Repository navigation
[lexical][lexical-mark] Bug Fix: $wrapSelectionInMarkNode with element points - #7132
Merged
Merged
Conversation
… with element points; add dev invariant for PointType type correctness
etrepum
requested review from
Fetz,
Sahejkm,
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
February 4, 2025 19:02
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ivailop7
approved these changes
Feb 4, 2025
This branch was successfully deployed
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
$wrapSelectionInMarkNodehad incorrect logic for dealing with point offsets, and the tests were written to work with this incorrect logic.This PR fixes that logic and adds a
__DEV__invariant to PointType to check that we are not setting text or element points with the wrong type of node (AFAIK this test suite was the only place doing this incorrectly). The logic was much simpler onceextract()was used instead ofgetNodes().There is some risk if there is code that is specifically creating invalid points to work around this issue as the tests were written, instead of the correct workaround which would've been to normalize the endpoints of the selection to text nodes.
There is some other risk with the new
PointType.setinvariant, but only in__DEV__, and this is only identifying potential problems that would've been hard to debug elsewhere.Test plan
Before
$caretFromPointcode has a similar invariant$wrapSelectionInMarkNodecode was incorrectAfter
Everything should work as before, but the way it was supposed to.
Follow-up considerations
I think as a follow up this API could change to deprecate isBackwards. It doesn't do anything useful, and it can be inferred from the RangeSelection.
I noticed that the original code would almost certainly behave incorrectly with a backwards selection in most multi-node cases, which I fixed by flipping the selection. The existing tests did not cover this case and I did not write additional tests to cover that case (but it should be fixed).