diff --git a/.changeset/tall-gorillas-deny.md b/.changeset/tall-gorillas-deny.md new file mode 100644 index 000000000..6258f548e --- /dev/null +++ b/.changeset/tall-gorillas-deny.md @@ -0,0 +1,5 @@ +--- +'slate': patch +--- + +Correct core normalization that could cause wrong nodes to be removed diff --git a/packages/slate/src/create-editor.ts b/packages/slate/src/create-editor.ts index d6b09efd7..1b95b2939 100644 --- a/packages/slate/src/create-editor.ts +++ b/packages/slate/src/create-editor.ts @@ -245,7 +245,7 @@ export const createEditor = (): Editor => { for (let i = 0; i < node.children.length; i++, n++) { const currentNode = Node.get(editor, path) if (Text.isText(currentNode)) continue - const child = node.children[i] as Descendant + const child = currentNode.children[n] as Descendant const prev = currentNode.children[n - 1] as Descendant const isLast = i === node.children.length - 1 const isInlineOrText = diff --git a/packages/slate/test/normalization/block/remove-inline.tsx b/packages/slate/test/normalization/block/remove-inline.tsx index 908440ada..cbe6e8782 100644 --- a/packages/slate/test/normalization/block/remove-inline.tsx +++ b/packages/slate/test/normalization/block/remove-inline.tsx @@ -6,6 +6,8 @@ export const input = ( one two + three + four ) @@ -13,6 +15,7 @@ export const output = ( one + three ) diff --git a/packages/slate/test/normalization/editor/remove-inline.tsx b/packages/slate/test/normalization/editor/remove-inline.tsx index e6caadc28..a990c8e96 100644 --- a/packages/slate/test/normalization/editor/remove-inline.tsx +++ b/packages/slate/test/normalization/editor/remove-inline.tsx @@ -5,10 +5,13 @@ export const input = ( one two + three + four ) export const output = ( two + four ) diff --git a/packages/slate/test/normalization/editor/remove-text.tsx b/packages/slate/test/normalization/editor/remove-text.tsx index aefd94d3e..e19c57290 100644 --- a/packages/slate/test/normalization/editor/remove-text.tsx +++ b/packages/slate/test/normalization/editor/remove-text.tsx @@ -5,10 +5,13 @@ export const input = ( one two + three + four ) export const output = ( two + four ) diff --git a/packages/slate/test/normalization/inline/remove-block.tsx b/packages/slate/test/normalization/inline/remove-block.tsx index f8c7d292a..ad0e8a622 100644 --- a/packages/slate/test/normalization/inline/remove-block.tsx +++ b/packages/slate/test/normalization/inline/remove-block.tsx @@ -8,6 +8,8 @@ export const input = ( one two + three + four @@ -18,7 +20,7 @@ export const output = ( - two + twofour