MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / getOffsets

Function getOffsets

code/composition/public/app.js:6472–6502  ·  view source on GitHub ↗

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

(outerNode)

Source from the content-addressed store, hash-verified

6470 * @return {?object}
6471 */
6472function getOffsets(outerNode) {
6473 var selection = window.getSelection && window.getSelection();
6474
6475 if (!selection || selection.rangeCount === 0) {
6476 return null;
6477 }
6478
6479 var anchorNode = selection.anchorNode,
6480 anchorOffset = selection.anchorOffset,
6481 focusNode = selection.focusNode,
6482 focusOffset = selection.focusOffset;
6483
6484 // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
6485 // up/down buttons on an <input type="number">. Anonymous divs do not seem to
6486 // expose properties, triggering a "Permission denied error" if any of its
6487 // properties are accessed. The only seemingly possible way to avoid erroring
6488 // is to access a property that typically works for non-anonymous divs and
6489 // catch any error that may otherwise arise. See
6490 // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
6491
6492 try {
6493 /* eslint-disable no-unused-expressions */
6494 anchorNode.nodeType;
6495 focusNode.nodeType;
6496 /* eslint-enable no-unused-expressions */
6497 } catch (e) {
6498 return null;
6499 }
6500
6501 return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
6502}
6503
6504/**
6505 * Returns {start, end} where `start` is the character/codepoint index of

Callers 1

getSelection$1Function · 0.70

Calls 1

Tested by

no test coverage detected