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

Function getOffsets

code/communication/public/app.js:6369–6399  ·  view source on GitHub ↗

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

(outerNode)

Source from the content-addressed store, hash-verified

6367 * @return {?object}
6368 */
6369function getOffsets(outerNode) {
6370 var selection = window.getSelection && window.getSelection();
6371
6372 if (!selection || selection.rangeCount === 0) {
6373 return null;
6374 }
6375
6376 var anchorNode = selection.anchorNode,
6377 anchorOffset = selection.anchorOffset,
6378 focusNode = selection.focusNode,
6379 focusOffset = selection.focusOffset;
6380
6381 // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
6382 // up/down buttons on an <input type="number">. Anonymous divs do not seem to
6383 // expose properties, triggering a "Permission denied error" if any of its
6384 // properties are accessed. The only seemingly possible way to avoid erroring
6385 // is to access a property that typically works for non-anonymous divs and
6386 // catch any error that may otherwise arise. See
6387 // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
6388
6389 try {
6390 /* eslint-disable no-unused-expressions */
6391 anchorNode.nodeType;
6392 focusNode.nodeType;
6393 /* eslint-enable no-unused-expressions */
6394 } catch (e) {
6395 return null;
6396 }
6397
6398 return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
6399}
6400
6401/**
6402 * 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