1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-02 03:32:36 +02:00

Do not remove empty node in merge operation if it is first children i… (#4287)

* Do not remove empty node in merge operation if it is first children in parent(#4228)

* Create merge-nodes-issue

* fix typo in changeset

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
liangxiwei
2021-08-06 01:38:31 +08:00
committed by GitHub
parent 0188980796
commit 13b3f9c783
2 changed files with 9 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"slate": patch
---
Do not remove empty node in merge operation if it is first children in its parent.

View File

@@ -422,9 +422,12 @@ export const NodeTransforms: NodeTransforms = {
// of merging the two. This is a common rich text editor behavior to // of merging the two. This is a common rich text editor behavior to
// prevent losing formatting when deleting entire nodes when you have a // prevent losing formatting when deleting entire nodes when you have a
// hanging selection. // hanging selection.
// if prevNode is first child in parent,don't remove it.
if ( if (
(Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode)) || (Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode)) ||
(Text.isText(prevNode) && prevNode.text === '') (Text.isText(prevNode) &&
prevNode.text === '' &&
prevPath[prevPath.length - 1] !== 0)
) { ) {
Transforms.removeNodes(editor, { at: prevPath, voids }) Transforms.removeNodes(editor, { at: prevPath, voids })
} else { } else {