MCPcopy Create free account
hub / github.com/reactjs/react-rails / getOffsets

Function getOffsets

lib/assets/react-source/development/react.js:10419–10449  ·  view source on GitHub ↗

* @param {DOMElement} outerNode * @return {?object}

(outerNode)

Source from the content-addressed store, hash-verified

10417 */
10418
10419 function getOffsets(outerNode) {
10420 var ownerDocument = outerNode.ownerDocument;
10421 var win = ownerDocument && ownerDocument.defaultView || window;
10422 var selection = win.getSelection && win.getSelection();
10423
10424 if (!selection || selection.rangeCount === 0) {
10425 return null;
10426 }
10427
10428 var anchorNode = selection.anchorNode,
10429 anchorOffset = selection.anchorOffset,
10430 focusNode = selection.focusNode,
10431 focusOffset = selection.focusOffset; // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
10432 // up/down buttons on an <input type="number">. Anonymous divs do not seem to
10433 // expose properties, triggering a "Permission denied error" if any of its
10434 // properties are accessed. The only seemingly possible way to avoid erroring
10435 // is to access a property that typically works for non-anonymous divs and
10436 // catch any error that may otherwise arise. See
10437 // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
10438
10439 try {
10440 /* eslint-disable no-unused-expressions */
10441 anchorNode.nodeType;
10442 focusNode.nodeType;
10443 /* eslint-enable no-unused-expressions */
10444 } catch (e) {
10445 return null;
10446 }
10447
10448 return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
10449 }
10450 /**
10451 * Returns {start, end} where `start` is the character/codepoint index of
10452 * (anchorNode, anchorOffset) within the textContent of `outerNode`, and

Callers 1

getSelectionFunction · 0.85

Calls 1

Tested by

no test coverage detected