Skip to content

Commit

Permalink
Add guards for Firefox and Safari compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed May 4, 2017
1 parent 3c390ef commit 9e16980
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/renderers/dom/shared/ReactInputSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,27 @@ function getElementsWithSelections(acc, win) {
var doc;
try {
doc = win.document;
if (!doc) {
return acc;
}
} catch (e) {
return acc;
}
var element = null;
if (win.getSelection) {
var selection = win.getSelection();
var startNode = selection.anchorNode;
var endNode = selection.focusNode;
var startOffset = selection.anchorOffset;
var endOffset = selection.focusOffset;
if (startNode && startNode.childNodes.length) {
if (startNode.childNodes[startOffset] === endNode.childNodes[endOffset]) {
element = startNode.childNodes[startOffset];
}
} else {
element = startNode;
if (selection) {
var startNode = selection.anchorNode;
var endNode = selection.focusNode;
var startOffset = selection.anchorOffset;
var endOffset = selection.focusOffset;
if (startNode && startNode.childNodes.length) {
if (startNode.childNodes[startOffset] === endNode.childNodes[endOffset]) {
element = startNode.childNodes[startOffset];
}
} else {
element = startNode;
}
}
} else if (doc.selection) {
var range = doc.selection.createRange();
Expand Down

0 comments on commit 9e16980

Please sign in to comment.