[lexical-utils] fix: Backward selection was not being retained#7737
Merged
ivailop7 merged 3 commits intofacebook:mainfrom Aug 4, 2025
Merged
[lexical-utils] fix: Backward selection was not being retained#7737ivailop7 merged 3 commits intofacebook:mainfrom
ivailop7 merged 3 commits intofacebook:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
jvithlani
commented
Aug 4, 2025
| await expect(heightDifference).toBeLessThanOrEqual(5); | ||
| }); | ||
|
|
||
| test(`retain selection works with reverse selection`, async ({ |
Contributor
Author
There was a problem hiding this comment.
confirmed this fails on the main branch
etrepum
reviewed
Aug 4, 2025
Collaborator
etrepum
left a comment
There was a problem hiding this comment.
A simpler fix would be to use the isBackwards method of RangeSelection, e.g.
function $getOrderedSelectionPoints(selection: RangeSelection): [PointType, PointType] {
// there's no reason for this to be nullable when called from RangeSelection, that could be fixed
const points = selection.getStartEndPoints()!;
return selection.isBackward() ? points.reverse() : points;
}With this method to retrieve the anchor and focus, you could remove the broken direction code from rangeFromPoints altogether.
Contributor
Author
|
something like this @etrepum ? |
etrepum
approved these changes
Aug 4, 2025
Collaborator
etrepum
left a comment
There was a problem hiding this comment.
Yeah, this is what I was thinking, although not necessarily with all of the renaming (but that does make it clearer, so perfectly ok!)
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
Problem
The selectionAlwaysOnDisplay utility wasn't working correctly for right-to-left text selections (when users drag from right to left). The visual selection mark would not appear properly when the editor lost focus after making a right-to-left selection.
Root Cause
The issue was in the rangeFromPoints function in markSelection.ts. The function was only checking focusNode.isBefore(anchorNode) to determine selection direction, which works for selections across different DOM nodes but fails for selections within the same text node.
For same-node selections:
Left-to-right: anchor.offset < focus.offset (e.g., 5 → 10)
Right-to-left: anchor.offset > focus.offset (e.g., 10 → 5)
The original logic didn't account for this offset-based direction detection.
Solution
Enhanced the selection direction detection logic to handle both cases:
Closes #7736
Before
Screen.Recording.2025-08-04.at.6.55.16.PM.mov
After
Screen.Recording.2025-08-04.at.9.32.03.PM.mov