Skip to content

Commit

Permalink
Fix toSlatePoint in void nodes with nested editors if children are re…
Browse files Browse the repository at this point in the history
…ndered as the last child (#5054)
  • Loading branch information
BitPhinix authored Jul 22, 2022
1 parent f13cd6b commit 1cc0797
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-snails-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fix toSlatePoint in void nodes with nested editors if children are rendered as the last child
12 changes: 10 additions & 2 deletions packages/slate-react/src/plugin/react-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,16 @@ export const ReactEditor = {
}
} else if (voidNode) {
// For void nodes, the element with the offset key will be a cousin, not an
// ancestor, so find it by going down from the nearest void parent.
leafNode = voidNode.querySelector('[data-slate-leaf]')!
// ancestor, so find it by going down from the nearest void parent and taking the
// first one that isn't inside a nested editor.
const leafNodes = voidNode.querySelectorAll('[data-slate-leaf]')
for (let index = 0; index < leafNodes.length; index++) {
const current = leafNodes[index]
if (ReactEditor.hasDOMNode(editor, current)) {
leafNode = current
break
}
}

// COMPAT: In read-only editors the leaf is not rendered.
if (!leafNode) {
Expand Down

0 comments on commit 1cc0797

Please sign in to comment.