From e9be0f368d616b3ac4b63078679aeefca66f33bc Mon Sep 17 00:00:00 2001 From: shaheerkpzaigo Date: Fri, 24 Jan 2025 18:01:32 +0530 Subject: [PATCH 1/3] fix(ContextMenuPlugin): Enable deletion of additional node types in Delete Node option - Fixed an issue where Delete Node did not handle specific node types (image, inline-image, page-break, excalidraw, horizontal-rule). - Added support for these node types to ensure consistent deletion behavior. --- .../src/plugins/ContextMenuPlugin/index.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx index 36f51ecb2ba..c21125d01db 100644 --- a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx @@ -15,6 +15,7 @@ import { import { $getNearestNodeFromDOMNode, $getSelection, + $isNodeSelection, $isRangeSelection, COPY_COMMAND, CUT_COMMAND, @@ -181,6 +182,21 @@ export default function ContextMenuPlugin(): JSX.Element { .at(-2); ancestorNodeWithRootAsParent?.remove(); + } else if ($isNodeSelection(selection)) { + const selectedNodes = selection.getNodes(); + const deletableNodeTypes = new Set([ + 'image', + 'inline-image', + 'page-break', + 'excalidraw', + 'horizontal-rule', + ]); + + selectedNodes.forEach((node) => { + if (deletableNodeTypes.has(node.getType())) { + node.remove(); + } + }); } }, }), From 50eb70b81b66e89e09aa7ea120dfd2ea135ec157 Mon Sep 17 00:00:00 2001 From: shaheerkpzaigo Date: Sat, 25 Jan 2025 14:43:12 +0530 Subject: [PATCH 2/3] fix(ContextMenuPlugin): Enable deletion of additional node types in Delete Node option --- .../lexical-playground/src/plugins/ContextMenuPlugin/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx index c21125d01db..a8b1fea33ff 100644 --- a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx @@ -189,7 +189,7 @@ export default function ContextMenuPlugin(): JSX.Element { 'inline-image', 'page-break', 'excalidraw', - 'horizontal-rule', + 'horizontalrule', ]); selectedNodes.forEach((node) => { From 8cd035166a16c7d90eefd9efdfb26f0e5f8a094e Mon Sep 17 00:00:00 2001 From: shaheerkpzaigo Date: Mon, 27 Jan 2025 11:51:16 +0530 Subject: [PATCH 3/3] Resolved Suggestion Changes --- .../src/plugins/ContextMenuPlugin/index.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx index 1cb492c3afd..eeec5e02788 100644 --- a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx @@ -17,6 +17,7 @@ import { import { $getNearestNodeFromDOMNode, $getSelection, + $isDecoratorNode, $isNodeSelection, $isRangeSelection, COPY_COMMAND, @@ -186,16 +187,8 @@ export default function ContextMenuPlugin(): JSX.Element { ancestorNodeWithRootAsParent?.remove(); } else if ($isNodeSelection(selection)) { const selectedNodes = selection.getNodes(); - const deletableNodeTypes = new Set([ - 'image', - 'inline-image', - 'page-break', - 'excalidraw', - 'horizontalrule', - ]); - selectedNodes.forEach((node) => { - if (deletableNodeTypes.has(node.getType())) { + if ($isDecoratorNode(node)) { node.remove(); } });