From fe24e82d163c1eb694ca6f62fbc585552e1f144c Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 16 Oct 2017 10:31:27 -0700 Subject: [PATCH] fix to check range count before getting ranges, closes #1237 (#1239) --- packages/slate-react/src/components/content.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/slate-react/src/components/content.js b/packages/slate-react/src/components/content.js index 35d0a12db..e7b21e593 100644 --- a/packages/slate-react/src/components/content.js +++ b/packages/slate-react/src/components/content.js @@ -125,9 +125,10 @@ class Content extends React.Component { const { selection } = state const window = getWindow(this.element) const native = window.getSelection() + const { rangeCount } = native // 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 // DOM, blur it manually. @@ -143,7 +144,7 @@ class Content extends React.Component { if (selection.isUnset) return // Otherwise, figure out which DOM nodes should be selected... - const current = native.getRangeAt(0) + const current = !!rangeCount && native.getRangeAt(0) const range = findDOMRange(selection) if (!range) { @@ -153,6 +154,7 @@ class Content extends React.Component { // If the new range matches the current selection, do nothing. if ( + current && range.startContainer == current.startContainer && range.startOffset == current.startOffset && range.endContainer == current.endContainer &&