fix(richtext-lexical): do not remove adjacent paragraph node when inserting certain nodes in empty editor (#5061)
This commit is contained in:
committed by
Alessio Gravili
parent
1df3065884
commit
8d502d2cb7
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user