MCPcopy Create free account
hub / github.com/Lobos/react-ui / getNodeForCharacterOffset

Function getNodeForCharacterOffset

docs/lib/react.js:16903–16924  ·  view source on GitHub ↗

* Get object describing the nodes which contain characters at offset. * * @param {DOMElement|DOMTextNode} root * @param {number} offset * @return {?object}

(root, offset)

Source from the content-addressed store, hash-verified

16901 * @return {?object}
16902 */
16903function getNodeForCharacterOffset(root, offset) {
16904 var node = getLeafNode(root);
16905 var nodeStart = 0;
16906 var nodeEnd = 0;
16907
16908 while (node) {
16909 if (node.nodeType === 3) {
16910 nodeEnd = nodeStart + node.textContent.length;
16911
16912 if (nodeStart <= offset && nodeEnd >= offset) {
16913 return {
16914 node: node,
16915 offset: offset - nodeStart
16916 };
16917 }
16918
16919 nodeStart = nodeEnd;
16920 }
16921
16922 node = getLeafNode(getSiblingNode(node));
16923 }
16924}
16925
16926module.exports = getNodeForCharacterOffset;
16927},{}],128:[function(_dereq_,module,exports){

Callers 1

setModernOffsetsFunction · 0.85

Calls 2

getLeafNodeFunction · 0.85
getSiblingNodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…