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

Function getOffsets

code/third-party/public/app.js:5567–5597  ·  view source on GitHub ↗

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

(outerNode)

Source from the content-addressed store, hash-verified

5565 * @return {?object}
5566 */
5567function getOffsets(outerNode) {
5568 var selection = window.getSelection && window.getSelection();
5569
5570 if (!selection || selection.rangeCount === 0) {
5571 return null;
5572 }
5573
5574 var anchorNode = selection.anchorNode,
5575 anchorOffset = selection.anchorOffset,
5576 focusNode = selection.focusNode,
5577 focusOffset = selection.focusOffset;
5578
5579 // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
5580 // up/down buttons on an <input type="number">. Anonymous divs do not seem to
5581 // expose properties, triggering a "Permission denied error" if any of its
5582 // properties are accessed. The only seemingly possible way to avoid erroring
5583 // is to access a property that typically works for non-anonymous divs and
5584 // catch any error that may otherwise arise. See
5585 // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
5586
5587 try {
5588 /* eslint-disable no-unused-expressions */
5589 anchorNode.nodeType;
5590 focusNode.nodeType;
5591 /* eslint-enable no-unused-expressions */
5592 } catch (e) {
5593 return null;
5594 }
5595
5596 return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
5597}
5598
5599/**
5600 * 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