Skip to content

Commit

Permalink
Take previously added/removed nodes into account when fetching child …
Browse files Browse the repository at this point in the history
…node in core normalization (#5396)
  • Loading branch information
Moerphy authored Apr 18, 2023
1 parent 832e75f commit bc945eb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-gorillas-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': patch
---

Correct core normalization that could cause wrong nodes to be removed
2 changes: 1 addition & 1 deletion packages/slate/src/create-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 3 additions & 0 deletions packages/slate/test/normalization/block/remove-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ export const input = (
<block>
<block>one</block>
<inline>two</inline>
<block>three</block>
<inline>four</inline>
</block>
</editor>
)
export const output = (
<editor>
<block>
<block>one</block>
<block>three</block>
</block>
</editor>
)
3 changes: 3 additions & 0 deletions packages/slate/test/normalization/editor/remove-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ export const input = (
<editor>
<inline>one</inline>
<block>two</block>
<inline>three</inline>
<block>four</block>
</editor>
)
export const output = (
<editor>
<block>two</block>
<block>four</block>
</editor>
)
3 changes: 3 additions & 0 deletions packages/slate/test/normalization/editor/remove-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ export const input = (
<editor>
<text>one</text>
<block>two</block>
<text>three</text>
<block>four</block>
</editor>
)
export const output = (
<editor>
<block>two</block>
<block>four</block>
</editor>
)
4 changes: 3 additions & 1 deletion packages/slate/test/normalization/inline/remove-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const input = (
<inline>
<block>one</block>
<text>two</text>
<block>three</block>
<text>four</text>
</inline>
<text />
</block>
Expand All @@ -18,7 +20,7 @@ export const output = (
<block>
<text />
<inline>
<text>two</text>
<text>twofour</text>
</inline>
<text />
</block>
Expand Down

0 comments on commit bc945eb

Please sign in to comment.