1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-05 06:47:26 +02:00

fix to check range count before getting ranges, closes #1237 (#1239)

This commit is contained in:
Ian Storm Taylor
2017-10-16 10:31:27 -07:00
committed by GitHub
parent 893140a1d8
commit fe24e82d16

View File

@@ -125,9 +125,10 @@ class Content extends React.Component {
const { selection } = state const { selection } = state
const window = getWindow(this.element) const window = getWindow(this.element)
const native = window.getSelection() const native = window.getSelection()
const { rangeCount } = native
// If both selections are blurred, do nothing. // If both selections are blurred, do nothing.
if (!native.rangeCount && selection.isBlurred) return if (!rangeCount && selection.isBlurred) return
// If the selection has been blurred, but is still inside the editor in the // If the selection has been blurred, but is still inside the editor in the
// DOM, blur it manually. // DOM, blur it manually.
@@ -143,7 +144,7 @@ class Content extends React.Component {
if (selection.isUnset) return if (selection.isUnset) return
// Otherwise, figure out which DOM nodes should be selected... // Otherwise, figure out which DOM nodes should be selected...
const current = native.getRangeAt(0) const current = !!rangeCount && native.getRangeAt(0)
const range = findDOMRange(selection) const range = findDOMRange(selection)
if (!range) { if (!range) {
@@ -153,6 +154,7 @@ class Content extends React.Component {
// If the new range matches the current selection, do nothing. // If the new range matches the current selection, do nothing.
if ( if (
current &&
range.startContainer == current.startContainer && range.startContainer == current.startContainer &&
range.startOffset == current.startOffset && range.startOffset == current.startOffset &&
range.endContainer == current.endContainer && range.endContainer == current.endContainer &&