Skip to content

Commit

Permalink
fix: cut collapsed table cell won't crash the editor (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
saif-ellafi authored Nov 20, 2024
1 parent ea81e3c commit a1081a9
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ void _pasteRichClipboard(EditorState editorState, AppFlowyClipboardData data) {
}
}

bool _isNodeInsideTable(Node node) {
Node? current = node;
while (current != null) {
if (current.type == 'table') {
return true;
}
current = current.parent;
}
return false;
}

/// 2. delete selected content
void handleCut(EditorState editorState) {
handleCopy(editorState);
Expand All @@ -357,7 +368,7 @@ Future<void> deleteSelectedContent(EditorState editorState) async {
if (selection.isCollapsed) {
// if the selection is collapsed, delete the current node
final node = editorState.getNodeAtPath(selection.end.path);
if (node == null) {
if (node == null || _isNodeInsideTable(node)) {
return;
}
transaction.deleteNode(node);
Expand Down

0 comments on commit a1081a9

Please sign in to comment.