diff --git a/packages/richtext-lexical/src/field/features/Blocks/plugin/index.tsx b/packages/richtext-lexical/src/field/features/Blocks/plugin/index.tsx index 2ead139056..f471cb2989 100644 --- a/packages/richtext-lexical/src/field/features/Blocks/plugin/index.tsx +++ b/packages/richtext-lexical/src/field/features/Blocks/plugin/index.tsx @@ -39,8 +39,16 @@ export function BlocksPlugin(): JSX.Element | null { const { focus } = selection const focusNode = focus.getNode() - // First, delete currently selected node if it's an empty paragraph - if ($isParagraphNode(focusNode) && focusNode.getTextContentSize() === 0) { + // First, delete currently selected node if it's an empty paragraph and if there are sufficient + // paragraph nodes (more than 1) left in the parent node, so that we don't "trap" the user + if ( + $isParagraphNode(focusNode) && + focusNode.getTextContentSize() === 0 && + focusNode + .getParent() + .getChildren() + .filter((node) => $isParagraphNode(node)).length > 1 + ) { focusNode.remove() } diff --git a/packages/richtext-lexical/src/field/features/Relationship/plugins/index.tsx b/packages/richtext-lexical/src/field/features/Relationship/plugins/index.tsx index 3658f65843..ac1a40a38b 100644 --- a/packages/richtext-lexical/src/field/features/Relationship/plugins/index.tsx +++ b/packages/richtext-lexical/src/field/features/Relationship/plugins/index.tsx @@ -54,8 +54,16 @@ export function RelationshipPlugin(props?: RelationshipFeatureProps): JSX.Elemen const { focus } = selection const focusNode = focus.getNode() - // First, delete currently selected node if it's an empty paragraph - if ($isParagraphNode(focusNode) && focusNode.getTextContentSize() === 0) { + // First, delete currently selected node if it's an empty paragraph and if there are sufficient + // paragraph nodes (more than 1) left in the parent node, so that we don't "trap" the user + if ( + $isParagraphNode(focusNode) && + focusNode.getTextContentSize() === 0 && + focusNode + .getParent() + .getChildren() + .filter((node) => $isParagraphNode(node)).length > 1 + ) { focusNode.remove() } diff --git a/packages/richtext-lexical/src/field/features/Upload/plugin/index.tsx b/packages/richtext-lexical/src/field/features/Upload/plugin/index.tsx index 2be5cd9203..0c45d57e8c 100644 --- a/packages/richtext-lexical/src/field/features/Upload/plugin/index.tsx +++ b/packages/richtext-lexical/src/field/features/Upload/plugin/index.tsx @@ -53,8 +53,16 @@ export function UploadPlugin(): JSX.Element | null { const { focus } = selection const focusNode = focus.getNode() - // First, delete currently selected node if it's an empty paragraph - if ($isParagraphNode(focusNode) && focusNode.getTextContentSize() === 0) { + // First, delete currently selected node if it's an empty paragraph and if there are sufficient + // paragraph nodes (more than 1) left in the parent node, so that we don't "trap" the user + if ( + $isParagraphNode(focusNode) && + focusNode.getTextContentSize() === 0 && + focusNode + .getParent() + .getChildren() + .filter((node) => $isParagraphNode(node)).length > 1 + ) { focusNode.remove() }