1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-07-31 20:40:19 +02:00

fix: Prevent ReactEditor.toDOMRange crash in setDomSelection (#5741)

This commit is contained in:
Adrien Poupa
2024-11-19 13:19:24 -05:00
committed by GitHub
parent 644ebdc8f5
commit 90fbcdeff5
2 changed files with 13 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fix ReactEditor.toDOMRange crash in setDomSelection

View File

@@ -339,7 +339,7 @@ export const Editable = forwardRef(
const focusNode = domSelection.focusNode
let anchorNode
// COMPAT: In firefox the normal seletion way does not work
// COMPAT: In firefox the normal selection way does not work
// (https://github.com/ianstormtaylor/slate/pull/5486#issue-1820720223)
if (IS_FIREFOX && domSelection.rangeCount > 1) {
const firstRange = domSelection.getRangeAt(0)
@@ -412,8 +412,13 @@ export const Editable = forwardRef(
// Otherwise the DOM selection is out of sync, so update it.
state.isUpdatingSelection = true
const newDomRange: DOMRange | null =
selection && ReactEditor.toDOMRange(editor, selection)
let newDomRange: DOMRange | null = null
try {
newDomRange = selection && ReactEditor.toDOMRange(editor, selection)
} catch (e) {
// Ignore, dom and state might be out of sync
}
if (newDomRange) {
if (ReactEditor.isComposing(editor) && !IS_ANDROID) {