-
Notifications
You must be signed in to change notification settings - Fork 2k
[lexical-offset] Fix: @lexical/offset makes invalid selection #7581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[lexical-offset] Fix: @lexical/offset makes invalid selection #7581
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test to show that this solves the issue would be great
packages/lexical-offset/src/index.ts
Outdated
: startOffsetNode.start; | ||
const parent = startNode.getParentOrThrow(); | ||
startKey = parent.getKey(); | ||
startOffset = parent.getChildrenKeys().indexOf(startNode.getKey()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startOffset = parent.getChildrenKeys().indexOf(startNode.getKey()); | |
startOffset = startNode.getIndexWithinParent(); |
packages/lexical-offset/src/index.ts
Outdated
end > endOffsetNode.start ? endOffsetNode.end : endOffsetNode.start; | ||
const parent = endNode.getParentOrThrow(); | ||
endKey = parent.getKey(); | ||
endOffset = parent.getChildrenKeys().indexOf(endNode.getKey()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endOffset = parent.getChildrenKeys().indexOf(endNode.getKey()); | |
endOffset = endNode.getIndexWithinParent(); |
47fc2ac
to
f28469b
Compare
Thank you for your review!
|
f28469b
to
e9320c9
Compare
Can someone else take a close look at this one? I don't see any usage of |
With respect to collab specifically, only Looking at the original PR though, I'm pretty sure these start/end values are intended to be absolute offsets rather than offsets relative to the parent -- |
After having a closer look myself, it looks like @james-atticus is right and that this probably isn't the correct fix. I think if we are going to fix anything in this module we should have a more comprehensive test suite that shows that it handles the diffing and offset clamping as expected in more than just this one case, and include the behavior when nodes are nested (e.g. an inline element node is not covered by this test case) |
Thank you for reviewing, but I don't quite understand comments. I don't think this PR changed anything related to absolute offsets. Do I misunderstand something? |
Possibly not, I did not give it a very thorough audit because I would have to carefully read all of the code in context to make sure it is correct. There just aren’t enough tests, and absolutely no usage in the playground or examples, to give me any confidence that this module does what it’s supposed to do before or after this change. |
My mistake, @wataru-chocola is correct. I was assuming that the original behaviour (returning absolute offset) was intentional, but that's incorrect. For the
The part I'm still unsure on though is whether it's correct to drop the |
Description
Fixed anchor / focus offset of the selection created by OffsetView.createSelectionFromOffsets.
Closes #7580