Skip to content

Commit

Permalink
fix issue #3651 where initial click on a void block can cause the edi…
Browse files Browse the repository at this point in the history
…tor 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
  • Loading branch information
cameracker authored May 5, 2020
1 parent e25c30c commit f4ee75d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down

0 comments on commit f4ee75d

Please sign in to comment.