Skip to content

Commit

Permalink
[lexical-table] Bug Fix: Prevent error if pasted table has empty row (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored Jan 16, 2025
1 parent 0835029 commit f6377a3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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

0 comments on commit f6377a3

Please sign in to comment.