1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-17 13:38:37 +01:00

Fix toSlatePoint in void nodes with nested editors if children are rendered as the last child (#5054)

This commit is contained in:
Eric Meier 2022-07-23 01:27:10 +02:00 committed by GitHub
parent f13cd6b918
commit 1cc0797f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fix toSlatePoint in void nodes with nested editors if children are rendered as the last child

View File

@ -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) {