1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 16:44:22 +02:00

fix: toSlatePoint suppressThrow leaf without text node (#4813)

This commit is contained in:
Eric Meier
2022-01-28 02:09:05 +01:00
committed by GitHub
parent e998752989
commit a5fd62ddd6
2 changed files with 32 additions and 24 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Don't throw in toSlatePoint while using supressThrow if leaf has no text node

View File

@@ -491,7 +491,9 @@ export const ReactEditor = {
// Calculate how far into the text node the `nearestNode` is, so that we
// can determine what the offset relative to the text node is.
if (leafNode) {
textNode = leafNode.closest('[data-slate-node="text"]')!
textNode = leafNode.closest('[data-slate-node="text"]')
if (textNode) {
const window = ReactEditor.getWindow(editor)
const range = window.document.createRange()
range.setStart(textNode, 0)
@@ -518,6 +520,7 @@ export const ReactEditor = {
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
offset = contents.textContent!.length
domNode = textNode
}
} 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.