fix(richtext-lexical): do not remove adjacent paragraph node when inserting certain nodes in empty editor (#5061)

This commit is contained in:
Alessio Gravili
2024-02-12 14:27:58 +01:00
committed by Alessio Gravili
parent 1df3065884
commit 8d502d2cb7
3 changed files with 30 additions and 6 deletions

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
}