Skip to content

Commit

Permalink
Fix normalizeNode to keep text/inline nodes when removing blocks (i…
Browse files Browse the repository at this point in the history
…anstormtaylor#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
  • Loading branch information
ahoisl authored Nov 23, 2024
1 parent 1d857cf commit 920b749
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/core/normalize-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/normalization/block/remove-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const input = (
export const output = (
<editor>
<block>
<text>one</text>
<text>onetwo</text>
</block>
</editor>
)
2 changes: 1 addition & 1 deletion test/normalization/inline/remove-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const output = (
<block>
<text />
<inline>
<text>twofour</text>
<text>onetwothreefour</text>
</inline>
<text />
</block>
Expand Down

0 comments on commit 920b749

Please sign in to comment.