mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-26 08:34:28 +02:00
fix: toSlatePoint suppressThrow leaf without text node (#4813)
This commit is contained in:
5
.changeset/kind-olives-add.md
Normal file
5
.changeset/kind-olives-add.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Don't throw in toSlatePoint while using supressThrow if leaf has no text node
|
@@ -491,7 +491,9 @@ export const ReactEditor = {
|
|||||||
// Calculate how far into the text node the `nearestNode` is, so that we
|
// Calculate how far into the text node the `nearestNode` is, so that we
|
||||||
// can determine what the offset relative to the text node is.
|
// can determine what the offset relative to the text node is.
|
||||||
if (leafNode) {
|
if (leafNode) {
|
||||||
textNode = leafNode.closest('[data-slate-node="text"]')!
|
textNode = leafNode.closest('[data-slate-node="text"]')
|
||||||
|
|
||||||
|
if (textNode) {
|
||||||
const window = ReactEditor.getWindow(editor)
|
const window = ReactEditor.getWindow(editor)
|
||||||
const range = window.document.createRange()
|
const range = window.document.createRange()
|
||||||
range.setStart(textNode, 0)
|
range.setStart(textNode, 0)
|
||||||
@@ -518,6 +520,7 @@ export const ReactEditor = {
|
|||||||
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
|
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
|
||||||
offset = contents.textContent!.length
|
offset = contents.textContent!.length
|
||||||
domNode = textNode
|
domNode = textNode
|
||||||
|
}
|
||||||
} else if (voidNode) {
|
} else if (voidNode) {
|
||||||
// For void nodes, the element with the offset key will be a cousin, not an
|
// 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.
|
// ancestor, so find it by going down from the nearest void parent.
|
||||||
|
Reference in New Issue
Block a user