facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

fix(LexicalNode): fix inline decorator isSelected #5948

Open jason89521 opened 3 weeks ago

jason89521 commented 3 weeks ago

Why

I pressed shift + ArrowLeft at the beginning of the video, and then pressed BackSpace to delete the selection. You can see the image node is selected, but when I deleted the selection, it didn't been deleted. Actually, the image node was not selected.

At the second half of the video, I pressed shift + ArrowRight, the first image also showed that it was selected. However, the image node didn't been selected actually, so when I deleted the selection, the image node didn't been deleted.

https://github.com/facebook/lexical/assets/47748132/8b33a6fb-f6e1-41b1-b5cd-3aded298e3d4

What

Beside checking whether the selection is collapsed, we should also check non-collapsed situation.

How

First, check whether the node is an inline decorator node.

Then check whether the anchor is before the focus.

Additional Information

After this pr:

https://github.com/facebook/lexical/assets/47748132/f3e3257b-f26d-45d4-8322-672dda184d9e

vercel[bot] commented 3 weeks ago

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

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 4:14am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 4:14am
StyleT commented 3 weeks ago

Hi! Thanks for the contribution!

Can you pls write tests to cover this use case?

jason89521 commented 2 weeks ago

@StyleT added in c1d6ada!

jason89521 commented 1 week ago

@StyleT Hi, just a gentle nudge to see if you could take a moment to review this pull request when you have a chance. Thanks!