1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-15 19:54:02 +02:00

fix issue #3651 where initial click on a void block can cause the editor to crash (#3654)

* fix issue #3651 where initial click on a void block can cause the editor to crash

* simplify non null cast for editor to element weakmap retrieve

* get prettier to shut up

* fixed comment
This commit is contained in:
Cameron Ackerman
2020-05-05 10:31:01 -07:00
committed by GitHub
parent e25c30c7a8
commit f4ee75d13d

View File

@@ -145,9 +145,20 @@ export const Editable = (props: EditableProps) => {
return
}
// If the DOM selection is already correct, we're done.
// verify that the dom selection is in the editor
const editorElement = EDITOR_TO_ELEMENT.get(editor)!
let hasDomSelectionInEditor = false
if (
editorElement.contains(domSelection.anchorNode) &&
editorElement.contains(domSelection.focusNode)
) {
hasDomSelectionInEditor = true
}
// If the DOM selection is in the editor and the editor selection is already correct, we're done.
if (
hasDomSelection &&
hasDomSelectionInEditor &&
selection &&
Range.equals(ReactEditor.toSlateRange(editor, domSelection), selection)
) {