Skip to content
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

Fix getSelectedNode logic for forward selection #3609

Merged
merged 1 commit into from
Dec 22, 2022

Conversation

moy2010
Copy link
Contributor

@moy2010 moy2010 commented Dec 21, 2022

Fixes getSelectedNode logic for forward selection.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 21, 2022
@vercel
Copy link

vercel bot commented Dec 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
lexical ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Dec 21, 2022 at 5:10PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Dec 21, 2022 at 5:10PM (UTC)

@trueadm
Copy link
Collaborator

trueadm commented Dec 21, 2022

Can you explain why this change makes sense? As I'm struggling to understand it. Maybe a video or tests of some kind?

@moy2010
Copy link
Contributor Author

moy2010 commented Dec 21, 2022

Can you explain why this change makes sense? As I'm struggling to understand it. Maybe a video or tests of some kind?

Sure!

You can test this by copy/pasting this in the playground:

I am a link!

If you start selecting the word link starting from the letter l, isLink will be true, but it should stop being true as soon as you select the exclamation mark, since that is no longer a LinkNode.

If you do the same bu by selecting the word backwards you should see the correct behaviour.

@moy2010
Copy link
Contributor Author

moy2010 commented Dec 21, 2022

As for the explanation for why this makes sense, if we take the example given above you can see that the node being selected at the end of the selection (focus) is a TextNode, thus the existing logic which returns the focusNode if $isAtNodeEnd(anchor) returns true is incorrect.

Copy link
Collaborator

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation

@trueadm trueadm merged commit e0376ea into facebook:main Dec 22, 2022
@trueadm trueadm mentioned this pull request Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants