Check for null selection
getRangeAt(0) will throw on null selection. Add guard in ReactDOMSelection and DocumentSelection.
Josh Duck committed
Oct 11, 2013 at 12:46 UTC
58c392ae3b539ef1c5fbb1baef020ec3b92c44b1
1 file changed
+6
-1
src/core/ReactDOMSelection.js
+6
-1
@@ -56,10 +56,15 @@ function getIEOffsets(node) {
56
57
/**
58
* @param {DOMElement} node
59
- * @return {object}
59
+ * @return {?object}
60
*/
61
function getModernOffsets(node) {
62
var selection = window.getSelection();
63
+
64
+ if (selection.rangeCount === 0) {
65
+ return null;
66
+ }
67
+
68
var anchorNode = selection.anchorNode;
69
var anchorOffset = selection.anchorOffset;
70
var focusNode = selection.focusNode;