Skip to content

Commit

Permalink
Merge pull request #3461 from xbeeant/hotfix/mergeable-table-row-delete
Browse files Browse the repository at this point in the history
fix: delete last row will cause editor crash when `enableMerging: true`
  • Loading branch information
zbeyens authored Aug 23, 2024
2 parents 7ffa6de + 59efb65 commit 1c7c955
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/delete-table-when-delete-last-row.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-table': patch
---

fix delete last row will cause editor crash when `enableMerging: true`
13 changes: 12 additions & 1 deletion packages/table/src/merge/deleteRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import type {
TablePlugin,
} from '../types';

import { ELEMENT_TABLE } from '../createTablePlugin';
import { ELEMENT_TABLE, ELEMENT_TR } from '../createTablePlugin';
import { getTableColumnCount } from '../queries';
import { getRowSpan } from '../queries/getRowSpan';
import { getCellTypes } from '../utils';
import { deleteRowWhenExpanded } from './deleteRowWhenExpanded';
import { findCellByIndexes } from './findCellByIndexes';
import { getCellIndices } from './getCellIndices';
import { deleteTable } from '../transforms';

export const deleteTableMergeRow = <V extends Value>(
editor: PlateEditor<V>
Expand Down Expand Up @@ -110,6 +111,16 @@ export const deleteTableMergeRow = <V extends Value>(
| TTableCellElement
| undefined;

if (nextRow === undefined) {
const trEntry = getAboveNode(editor, {
match: { type: getPluginType(editor, ELEMENT_TR) },
});
if (trEntry && trEntry[0].children.length === 1) {
deleteTable(editor);

return
}
}
if (nextRow) {
moveToNextRowCells.forEach((cur, index) => {
const curRowCell = cur as TTableCellElement;
Expand Down

0 comments on commit 1c7c955

Please sign in to comment.