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 TableCell child nodes on paste #5951

Closed Shubhankerism closed 3 weeks ago

Shubhankerism commented 3 weeks ago

This PR fixes pasting tables that have the copied html in such format:

...
<td>
<span> ... </span>
</td>
...

Pasting this results in the following node structure:

image

which causes the editor to freeze and eventually crash on enter key press, as the text node is not wrapped in a paragraph node. This issue is similar to the one described here and was fixed for the case when pasting empty cells.

This PR addresses the case when on paste the children of the TableCell node are not within a block element node.

Another case to reproduce this issue is when we copy something with such html:

...
<td>
<a> ... </a>
</td>
...

This results in a link node inside a tablecell node which again crashes on enter key press.

Also, this PR fixes the issue with alignment of text inside the cell as well, as this formatting can now be applied on the wrapping block element node. So, copying from google sheets will now have the correct alignment.

Before

table-align-before

After

table-align-after

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 24, 2024 5:14pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 5:14pm
zurfyx commented 3 weeks ago

Thank you, we can merge this, but I'd be inclined to roll it back as soon as https://github.com/facebook/lexical/pull/5857 is ready as it fixes the same issue in a more generic manner cc @potatowagon

ivailop7 commented 3 weeks ago

Thanks Gerard! Happy to revert once the larger one lands. Do we have an ETA on the generic solution? If it's a week, we can wait it out.

potatowagon commented 2 weeks ago

5857 is ready, tests added and comments addressed @ivailop7 @zurfyx