-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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-react]: Fix incorrect addition of empty cells on table paste #6578
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
Fantastic! Well done! Please add a test for this copy-paste use case, there are quite a few to take inspiration from, so it should be easy to add one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to see some tests with various merged cell conditions, I'm not familiar enough with this code to judge if it's a general fix or only handles the cases you ran into. The indexing seems maybe a bit suspicious (e.g. if there are merges in the middle of the table), but I didn't review $computeTableMapSkipCellCheck
const row = gridMap[i].filter((cell) => cell); | ||
const rowLength = row.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're not using this array it would be more efficient to calculate it directly
const row = gridMap[i].filter((cell) => cell); | |
const rowLength = row.length; | |
const rowLength = gridMap[i].reduce((acc, cell) => cell ? 1 + acc : acc, 0); |
if (rowLength === maxRowLength) { | ||
continue; | ||
} | ||
const lastCellMap = gridMap[i][rowLength - 1]; | ||
const lastRowCell = lastCellMap.cell; | ||
const rowNode: TableRowNode | null = node.getChildAtIndex(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more efficient to compute node.getChildren()
outside of the loop and index it directly down here since each getChildAtIndex
is a linked list traversal in a loop this ends up being geometric instead of linear.
Could also do the if (rowNode)
here and continue or wrap it around the loop so you can skip the loop if it is merged.
@etrepum good with this one? |
This PR fixes the issue with empty cells getting incorrectly added to a table upon paste.
Before
When a table with rows with unequal sizes and merged cells is pasted, we add the empty cells in the wrong row.
For example, a table like this:
After
Empty cells are now added to the correct row.