diff --git a/lib/components/leaf.js b/lib/components/leaf.js index 8585c767c..6996c0599 100644 --- a/lib/components/leaf.js +++ b/lib/components/leaf.js @@ -64,18 +64,18 @@ class Leaf extends React.Component { const { node, start, end } = this.props // If neither matches, the selection doesn't start or end here, so exit. - const hasStart = selection.hasStartBetween(node, start, end) - const hasEnd = selection.hasEndBetween(node, start, end) - if (!hasStart && !hasEnd) return + const hasAnchor = selection.hasAnchorBetween(node, start, end) + const hasFocus = selection.hasFocusBetween(node, start, end) + if (!hasAnchor && !hasFocus) return // We have a selection to render, so prepare a few things... const native = window.getSelection() const el = ReactDOM.findDOMNode(this).firstChild // If both the start and end are here, set the selection all at once. - if (hasStart && hasEnd) { + if (hasAnchor && hasFocus) { native.removeAllRanges() - const range = document.createRange() + const range = window.document.createRange() range.setStart(el, anchorOffset - start) native.addRange(range) native.extend(el, focusOffset - start) @@ -86,12 +86,12 @@ class Leaf extends React.Component { // the first leaf to render, reset the selection and set the new start. And // then in the second leaf to render, extend to the new end. if (selection.isForward) { - if (hasStart) { + if (hasAnchor) { native.removeAllRanges() - const range = document.createRange() + const range = window.document.createRange() range.setStart(el, anchorOffset - start) native.addRange(range) - } else if (hasEnd) { + } else if (hasFocus) { native.extend(el, focusOffset - start) } } @@ -101,16 +101,16 @@ class Leaf extends React.Component { // end position. And then in the second leaf to render, set the start and // extend the end to the stored value. else { - if (hasEnd) { + if (hasFocus) { native.removeAllRanges() - const range = document.createRange() + const range = window.document.createRange() range.setStart(el, focusOffset - start) native.addRange(range) - } else if (hasStart) { + } else if (hasAnchor) { const endNode = native.focusNode const endOffset = native.focusOffset native.removeAllRanges() - const range = document.createRange() + const range = window.document.createRange() range.setStart(el, anchorOffset - start) native.addRange(range) native.extend(endNode, endOffset)