Skip to content

fix(richtext-lexical): prevent extra paragraph when inserting blocks or uploadNodes. Add preemptive selection normalization #12077

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GermanJablo
Copy link
Contributor

Fixes #11628 (partially, explanation below)

PR #6389 caused bug #11628, which is a regression, as it had already been fixed in #4441

I reverted those changes and was able to verify that the error didn't occur, even when I forced it programmatically. The changes in that PR were made because the selection sometimes ended up on deleted nodes, and Lexical would throw an error. Upon investigation, I found that Lexical had recently made improvements to address selection normalization.

Although it wasn't necessary to resolve the issue, I added a NormalizeSelectionPlugin to the editor, which makes selection handling in the editor more robust.

Partly because of what I explained above, and partly because I remember seeing several issues related to this bug, and I had the same problem a couple of weeks ago while developing a feature for the email builder.
So, what this plugin does is move the selection to the end of the editor if it doesn't find the selected nodes, instead of throwing an error.


Note: This PR fixes block insertion as it was before #6389. That is, no empty paragraphs are left, unless they are the first paragraph in the editor. This was because inserting a block at the beginning of the editor would otherwise be difficult due to lack of room to click.

However, looking at #11628's video, it seems users also want to be able to prevent the first paragraph from being empty. This makes sense to me, so I think in another PR we could add a button at the top, just like we did at the bottom of the editor.

…locks or uploadNodes. Add a preventative plugin to normalize the selection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lexical Block feature adds unnecessary paragraphs
1 participant