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-playground][lexical-table] Bug Fix: Resizing table with merged cells #6200

Merged
merged 6 commits into from
May 31, 2024

Conversation

AlexanderReznik
Copy link
Contributor

Changing how table resizing works

Changing the selection of cells that needs to be resized during resizing of a column

Current logic works nicely for the cases without merged cells, however it breaks after cells merging. I'm using $computeTableMapSkipCellCheck to create a mapping of cells to their coordinates on screen on every resize. And I think it might be beneficial to cache the map in the TableNode as it is useful for selection, resizing, navigation in a table with keyboard (that currently is also crashing with the merged cells). I'd appreciate the thoughts on whether it's possible to extend the TableNode.

Changing the logic for calculating new width/height of cells

Assuming that the new height/width of the cell that is active during the resize should be applied to all cells in the same row/column is incorrect because after merging cells in a table cells in the same row/column can have different height/width. This means the change in height/width should be applied to every cell that is resized.


Closes #5515

Test plan

I'm currently adding tests for the cases where resizing was breaking previously.

Before

Crash:
resize-crash

Wrong size:
resize-wrong-width

After

Right size:
resize-wrong-width-after

Copy link

vercel bot commented May 29, 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 May 30, 2024 3:06pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2024 3:06pm

@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 May 29, 2024
Copy link

github-actions bot commented May 29, 2024

size-limit report 📦

Path Size
lexical 23.95 KB (0%)
@lexical/rich-text 34.64 KB (0%)
@lexical/plain-text 34.62 KB (0%)
@lexical/react 149.36 KB (0%)

@@ -178,6 +182,17 @@ function TableCellResizer({editor}: {editor: LexicalEditor}): JSX.Element {
throw new Error('Expected table row');
}

let height = tableRow.getHeight();
if (!height) {
Copy link
Contributor

@potatowagon potatowagon May 30, 2024

Choose a reason for hiding this comment

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

hi! really appreciate this fix! leaving some suggestions to make the code clearer

lets preferably avoid sketchy null checks. since height is number | undefined, if height = 0, it will be lumped under the undefined case.

hence would be great to have explicit if conditions, such as if (height === undefined || height === 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense!
Changed to more specific checks in 9fa9e0f

Copy link
Contributor

Choose a reason for hiding this comment

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

thankyou for the updates!

activeEditor: LexicalEditor,
): number | undefined => {
const width = cell.getWidth();
if (width) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here for sketchy null check, if width = 0 should this if block be skipped?

}

const domCellNode = activeEditor.getElementByKey(cell.getKey());
if (!domCellNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!domCellNode) {
if (domCellNode == null) {

if (!$isTableCellNode(tableCell)) {
throw new Error('Expected table cell');
const width = getCellNodeWidth(cell.cell, editor);
if (!width) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!width) {
if (width === undefined) {

potatowagon
potatowagon previously approved these changes May 30, 2024
Copy link
Contributor

@potatowagon potatowagon left a comment

Choose a reason for hiding this comment

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

great fix thankyou!

@potatowagon potatowagon added this pull request to the merge queue May 31, 2024
Merged via the queue into facebook:main with commit 4af83c1 May 31, 2024
12 of 13 checks passed
@Sahejkm
Copy link
Contributor

Sahejkm commented May 31, 2024

Hi @AlexanderReznik this PR is actually failing the CI , the newly added e2e tests written are failing ,

example: https://github.com/facebook/lexical/actions/runs/9311543149/job/25630871373?pr=6216

Sorry we missed adding extended-tests label before merging this PR, could you help look into this ?

Thank you!

Sahejkm added a commit that referenced this pull request May 31, 2024
@AlexanderReznik
Copy link
Contributor Author

Hi @AlexanderReznik this PR is actually failing the CI , the newly added e2e tests written are failing ,

example: https://github.com/facebook/lexical/actions/runs/9311543149/job/25630871373?pr=6216

Sorry we missed adding extended-tests label before merging this PR, could you help look into this ?

Thank you!

Yes, sure, I'll have a look!

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: This is a bug where the table width cannot be adjusted after merging cells.
4 participants