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: Prevent error if pasted table has empty row #7057

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,58 @@ test.describe('HTML Tables CopyAndPaste', () => {
`,
);
});

test('Copy + paste table with empty row', async ({
page,
isPlainText,
isCollab,
}) => {
test.skip(isPlainText);

await focusEditor(page);

const clipboard = {
'text/html': html`
<table>
<tr><td>1</td></tr>
<tr></tr>
<tr><td>2</td></tr>
</table>
`,
};

await pasteFromClipboard(page, clipboard);

await assertHTML(
page,
html`
<table class="PlaygroundEditorTheme__table">
<colgroup>
<col style="width: 92px" />
</colgroup>
<tr>
<td class="PlaygroundEditorTheme__tableCell">
<p class="PlaygroundEditorTheme__paragraph">
<span data-lexical-text="true">1</span>
</p>
</td>
</tr>
<tr>
<td class="PlaygroundEditorTheme__tableCell">
<p class="PlaygroundEditorTheme__paragraph">
<br />
</p>
</td>
</tr>
<tr>
<td class="PlaygroundEditorTheme__tableCell">
<p class="PlaygroundEditorTheme__paragraph">
<span data-lexical-text="true">2</span>
</p>
</td>
</tr>
</table>
`,
);
});
});
2 changes: 1 addition & 1 deletion packages/lexical-table/src/LexicalTableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ export function $computeTableMapSkipCellCheck(
$isTableRowNode(row),
'Expected TableNode children to be TableRowNode',
);
const startMapRow = getMapRow(rowIdx);
for (
let cell = row.getFirstChild(), colIdx = 0;
cell != null;
Expand All @@ -866,7 +867,6 @@ export function $computeTableMapSkipCellCheck(
'Expected TableRowNode children to be TableCellNode',
);
// Skip past any columns that were merged from a higher row
const startMapRow = getMapRow(rowIdx);
while (startMapRow[colIdx] !== undefined) {
colIdx++;
}
Expand Down
Loading