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 Nov 1, 2017
1 parent f6f9e35 commit 6ac703f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/react-dom/src/client/ReactInputSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,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 6ac703f

Please sign in to comment.