Check for null selection

getRangeAt(0) will throw on null selection. Add guard in
ReactDOMSelection and DocumentSelection.
This commit is contained in:
Josh Duck
2013-10-11 12:52:19 -07:00
committed by Paul O’Shannessy
parent 4549fd7510
commit 58c392ae3b
+6 -1
View File
@@ -56,10 +56,15 @@ function getIEOffsets(node) {
/**
* @param {DOMElement} node
* @return {object}
* @return {?object}
*/
function getModernOffsets(node) {
var selection = window.getSelection();
if (selection.rangeCount === 0) {
return null;
}
var anchorNode = selection.anchorNode;
var anchorOffset = selection.anchorOffset;
var focusNode = selection.focusNode;