From bc945eb12c612ef2688869d256416c8e37e32c07 Mon Sep 17 00:00:00 2001 From: void Date: Tue, 18 Apr 2023 14:00:33 +0200 Subject: [PATCH] Take previously added/removed nodes into account when fetching child node in core normalization (#5396) --- .changeset/tall-gorillas-deny.md | 5 +++++ packages/slate/src/create-editor.ts | 2 +- packages/slate/test/normalization/block/remove-inline.tsx | 3 +++ packages/slate/test/normalization/editor/remove-inline.tsx | 3 +++ packages/slate/test/normalization/editor/remove-text.tsx | 3 +++ packages/slate/test/normalization/inline/remove-block.tsx | 4 +++- 6 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/tall-gorillas-deny.md 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