mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +02:00
fix: Prevent ReactEditor.toDOMRange crash in setDomSelection (#5741)
This commit is contained in:
5
.changeset/serious-eels-pay.md
Normal file
5
.changeset/serious-eels-pay.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix ReactEditor.toDOMRange crash in setDomSelection
|
@@ -339,7 +339,7 @@ export const Editable = forwardRef(
|
|||||||
const focusNode = domSelection.focusNode
|
const focusNode = domSelection.focusNode
|
||||||
let anchorNode
|
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)
|
// (https://github.com/ianstormtaylor/slate/pull/5486#issue-1820720223)
|
||||||
if (IS_FIREFOX && domSelection.rangeCount > 1) {
|
if (IS_FIREFOX && domSelection.rangeCount > 1) {
|
||||||
const firstRange = domSelection.getRangeAt(0)
|
const firstRange = domSelection.getRangeAt(0)
|
||||||
@@ -412,8 +412,13 @@ export const Editable = forwardRef(
|
|||||||
// Otherwise the DOM selection is out of sync, so update it.
|
// Otherwise the DOM selection is out of sync, so update it.
|
||||||
state.isUpdatingSelection = true
|
state.isUpdatingSelection = true
|
||||||
|
|
||||||
const newDomRange: DOMRange | null =
|
let newDomRange: DOMRange | null = null
|
||||||
selection && ReactEditor.toDOMRange(editor, selection)
|
|
||||||
|
try {
|
||||||
|
newDomRange = selection && ReactEditor.toDOMRange(editor, selection)
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore, dom and state might be out of sync
|
||||||
|
}
|
||||||
|
|
||||||
if (newDomRange) {
|
if (newDomRange) {
|
||||||
if (ReactEditor.isComposing(editor) && !IS_ANDROID) {
|
if (ReactEditor.isComposing(editor) && !IS_ANDROID) {
|
||||||
|
Reference in New Issue
Block a user