mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-13 18:53:59 +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:
5
.changeset/large-cars-itch.md
Normal file
5
.changeset/large-cars-itch.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Keep data in normalization when blocks are not allowed
|
@@ -53,7 +53,11 @@ export const normalizeNode: WithEditorFirstArg<Editor['normalizeNode']> = (
|
|||||||
// other inline nodes, or parent blocks that only contain inlines and
|
// other inline nodes, or parent blocks that only contain inlines and
|
||||||
// text.
|
// text.
|
||||||
if (isInlineOrText !== shouldHaveInlines) {
|
if (isInlineOrText !== shouldHaveInlines) {
|
||||||
|
if (isInlineOrText) {
|
||||||
Transforms.removeNodes(editor, { at: path.concat(n), voids: true })
|
Transforms.removeNodes(editor, { at: path.concat(n), voids: true })
|
||||||
|
} else {
|
||||||
|
Transforms.unwrapNodes(editor, { at: path.concat(n), voids: true })
|
||||||
|
}
|
||||||
n--
|
n--
|
||||||
} else if (Element.isElement(child)) {
|
} else if (Element.isElement(child)) {
|
||||||
// Ensure that inline nodes are surrounded by text nodes.
|
// Ensure that inline nodes are surrounded by text nodes.
|
||||||
|
@@ -12,7 +12,7 @@ export const input = (
|
|||||||
export const output = (
|
export const output = (
|
||||||
<editor>
|
<editor>
|
||||||
<block>
|
<block>
|
||||||
<text>one</text>
|
<text>onetwo</text>
|
||||||
</block>
|
</block>
|
||||||
</editor>
|
</editor>
|
||||||
)
|
)
|
||||||
|
@@ -20,7 +20,7 @@ export const output = (
|
|||||||
<block>
|
<block>
|
||||||
<text />
|
<text />
|
||||||
<inline>
|
<inline>
|
||||||
<text>twofour</text>
|
<text>onetwothreefour</text>
|
||||||
</inline>
|
</inline>
|
||||||
<text />
|
<text />
|
||||||
</block>
|
</block>
|
||||||
|
Reference in New Issue
Block a user