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 Mar 15, 2017
1 parent 6bc746a commit f8b202d
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 @@ -41,22 +41,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 f8b202d

Please sign in to comment.