Skip to content

Commit

Permalink
Fix another bug
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverWales committed Aug 31, 2023
1 parent 651ea4f commit d681ba6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/table/src/transforms/deleteColumn.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('deleteColumn', () => {
});

describe('when first row has 2 cells, second row has 1 cell, focus 11', () => {
it('should do nothing', () => {
it('should delete 11', () => {
const input = (
<editor>
<htable>
Expand Down
10 changes: 8 additions & 2 deletions packages/table/src/transforms/deleteColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ export const deleteColumn = <V extends Value>(editor: PlateEditor<V>) => {
tableNode.children.forEach((row, rowIdx) => {
pathToDelete[replacePathPos] = rowIdx;

// for rows with different lengths
if (colIndex > (row.children as TElement[]).length - 1) return;
// for tables containing rows of different lengths
// - don't delete if only one cell in row
// - don't delete if row doesn't have this cell
if (
(row.children as TElement[]).length === 1 ||
colIndex > (row.children as TElement[]).length - 1
)
return;

removeNodes(editor, {
at: pathToDelete,
Expand Down

0 comments on commit d681ba6

Please sign in to comment.