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

[lexical-table] Bug Fix: Resolve table selection issue when the mouse crosses over a portal #6834

Merged
merged 25 commits into from
Nov 24, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Nov 14, 2024

Description

When using table selection by mouse movement, if the mouse crosses over an element that is outside of the document, it ends up creating a native selection that messes up the intended table selection.

Unfortunately when researching this bug I accidentally learned how much of a tangled un-idiomatic mess this plugin is and I couldn't figure out how to fix it without a larger refactoring. The primary anti-patterns are basically nested and cascading updates.

For whatever historical reason, lexical uses the most error-prone design imaginable for nested updates, so they should be avoided at all cost (surprisingly, dispatchCommand avoids this issue by working in the manner that nested updates should have been implemented). TableObserver's methods are primarily used inside updates, but because sometimes they are called from mouse events they all have an explicit editor.update which is a mistake. I've renamed them all to $methods to be explicit on their dependencies and how to use them.

By doing this in a way that actually makes sense for Lexical, we will probably fix some bugs we don't know about yet, remove the cascading updates, and remove the setTimeout nonsense that was used to work around the nested and cascading updates.

This is not a complete refactor, just enough to get things working. I'm sure more logic could be cleaned up here, especially regarding nested tables.

Closes #6820
Closes #6861 (the code from that PR is also here)

Test plan

Before

table-action-cell-button-select.mov

After

table-action-cell-button-hide.mov

@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 Nov 14, 2024
Copy link

vercel bot commented Nov 14, 2024

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 Nov 24, 2024 1:02am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 24, 2024 1:02am

Copy link

github-actions bot commented Nov 14, 2024

size-limit report 📦

Path Size
lexical - cjs 30.95 KB (0%)
lexical - esm 30.76 KB (0%)
@lexical/rich-text - cjs 39.62 KB (0%)
@lexical/rich-text - esm 32.66 KB (0%)
@lexical/plain-text - cjs 38.21 KB (0%)
@lexical/plain-text - esm 29.9 KB (0%)
@lexical/react - cjs 41.32 KB (0%)
@lexical/react - esm 34.06 KB (0%)

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Nov 14, 2024
@etrepum etrepum marked this pull request as draft November 14, 2024 19:40
Copy link
Collaborator

@ivailop7 ivailop7 left a comment

Choose a reason for hiding this comment

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

Fantastic work! Really well done, Bob!

@etrepum etrepum added this pull request to the merge queue Nov 24, 2024
Merged via the queue into facebook:main with commit fcb7666 Nov 24, 2024
40 checks passed
@etrepum etrepum deleted the table-cell-action-button-selection branch November 24, 2024 18:58
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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [lexical-table] Dragging over the table-cell-action-button interferes with selection
3 participants