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

Bug: TableComponent exception occurs when all cells are selected for deletion and the last cell is blank. A table with one blank cell will be left. #3965

Open
Croc-ye opened this issue Jan 13, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Croc-ye
Copy link
Contributor

Croc-ye commented Jan 13, 2025

Description

企业微信截图_2352b092-bf13-4fda-a4d4-b9468a1aa589
企业微信20250113-110334

Reproduction URL

No response

Reproduction steps

1. Go to 'https://platejs.org/'
2. Click on 'Table'
3. select all table cells and the last cell is empty
4. enter delete
5. error happened

Plate version

42.0.0

Slate React version

0.112.0

Screenshots

No response

Logs

No response

Browsers

Chrome

@Croc-ye Croc-ye added the bug Something isn't working label Jan 13, 2025
@Croc-ye
Copy link
Contributor Author

Croc-ye commented Jan 13, 2025

I have a preliminary plan. Please help me see if it is feasible.

  editor.deleteFragment = (direction) => {
    if (
      isRangeInSameBlock(editor, {
        match: n => n.type === type,
      })
    ) {
      const cellEntries = getTableGridAbove(editor, { format: 'cell' });

      if (cellEntries.length > 1) {
        withoutNormalizing(editor, () => {
          cellEntries.forEach(([, cellPath]) => {
            replaceNodeChildren<TElement>(editor, {
              at: cellPath,
              nodes: editor.api.create.block(),
            });
          });

          // set back the selection
          select(editor, {
            anchor: getStartPoint(editor, cellEntries[0][1]),
            focus: getEndPoint(editor, cellEntries.at(-1)![1]),
          });
        });

        return;
      }
    } else if (editor.selection && isExpanded(editor.selection)) {
      const tableNode1 = getTableAbove(editor, {
        at: editor.selection.anchor,
      });
      const tableNode2 = getTableAbove(editor, {
        at: editor.selection.focus,
      });
      const [start] = editor.edges([]);
      if (
        (tableNode1 || tableNode2)
        && (Point.equals(start, editor.selection.focus)
          || Point.equals(start, editor.selection.anchor))
      ) {
        editor.removeNodes({
          at: tableNode1?.[1] || tableNode2?.[1],
        });
      }
    }

    deleteFragment(direction);
  };

in withDeleteTable.ts

@zbeyens
Copy link
Member

zbeyens commented Jan 13, 2025

Writing a unit test would be best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants