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:
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
|
||||
// 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.
|
||||
|
@@ -12,7 +12,7 @@ export const input = (
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<text>one</text>
|
||||
<text>onetwo</text>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
@@ -20,7 +20,7 @@ export const output = (
|
||||
<block>
|
||||
<text />
|
||||
<inline>
|
||||
<text>twofour</text>
|
||||
<text>onetwothreefour</text>
|
||||
</inline>
|
||||
<text />
|
||||
</block>
|
||||
|
Reference in New Issue
Block a user