Skip to content

Commit

Permalink
Merge pull request udecode#2594 from OliverWales/fix-delete-column
Browse files Browse the repository at this point in the history
Fix column deletion early return
  • Loading branch information
zbeyens authored Sep 1, 2023
2 parents 0ffad8d + d681ba6 commit af41503
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-singers-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-table": patch
---

Fix column deletion early return
2 changes: 1 addition & 1 deletion packages/table/src/queries/isTableBorderHidden.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @jsx jsx */

import { createPlateEditor, PlateEditor } from '@udecode/plate-common';
import { createTablePlugin } from '@udecode/plate-table';
import { jsx } from '@udecode/plate-test-utils';

import { createTablePlugin } from '../createTablePlugin';
import { isTableBorderHidden } from './isTableBorderHidden';

jsx;
Expand Down
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
12 changes: 9 additions & 3 deletions packages/table/src/transforms/deleteColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ export const deleteColumn = <V extends Value>(editor: PlateEditor<V>) => {
const replacePathPos = pathToDelete.length - 2;

withoutNormalizing(editor, () => {
tableEntry[0].children.forEach((row, rowIdx) => {
tableNode.children.forEach((row, rowIdx) => {
pathToDelete[replacePathPos] = rowIdx;

// for rows with different lengths
if ((row.children as TElement[]).length < replacePathPos + 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 af41503

Please sign in to comment.