1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-07-31 20:40:19 +02:00

Fix normalizeNode to keep text/inline nodes when removing blocks (#5768)

* fix: fix data loss in base `normalizeData` if no blocks allowed

Use `unwrapNodes` instead of `removeNodes` to
convert block to inline/text nodes.

* changeset
This commit is contained in:
Alex
2024-11-23 01:01:11 +01:00
committed by GitHub
parent 90fbcdeff5
commit 4bc552f71f
4 changed files with 12 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': patch
---
Keep data in normalization when blocks are not allowed

View File

@@ -53,7 +53,11 @@ export const normalizeNode: WithEditorFirstArg<Editor['normalizeNode']> = (
// other inline nodes, or parent blocks that only contain inlines and
// text.
if (isInlineOrText !== shouldHaveInlines) {
Transforms.removeNodes(editor, { at: path.concat(n), voids: true })
if (isInlineOrText) {
Transforms.removeNodes(editor, { at: path.concat(n), voids: true })
} else {
Transforms.unwrapNodes(editor, { at: path.concat(n), voids: true })
}
n--
} else if (Element.isElement(child)) {
// Ensure that inline nodes are surrounded by text nodes.

View File

@@ -12,7 +12,7 @@ export const input = (
export const output = (
<editor>
<block>
<text>one</text>
<text>onetwo</text>
</block>
</editor>
)

View File

@@ -20,7 +20,7 @@ export const output = (
<block>
<text />
<inline>
<text>twofour</text>
<text>onetwothreefour</text>
</inline>
<text />
</block>