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

Function getNodeForCharacterOffset

code/redux/public/app.js:6558–6579  ·  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

6556 * @return {?object}
6557 */
6558function getNodeForCharacterOffset(root, offset) {
6559 var node = getLeafNode(root);
6560 var nodeStart = 0;
6561 var nodeEnd = 0;
6562
6563 while (node) {
6564 if (node.nodeType === TEXT_NODE) {
6565 nodeEnd = nodeStart + node.textContent.length;
6566
6567 if (nodeStart <= offset && nodeEnd >= offset) {
6568 return {
6569 node: node,
6570 offset: offset - nodeStart
6571 };
6572 }
6573
6574 nodeStart = nodeEnd;
6575 }
6576
6577 node = getLeafNode(getSiblingNode(node));
6578 }
6579}
6580
6581/**
6582 * @param {DOMElement} outerNode

Callers 1

setOffsetsFunction · 0.70

Calls 2

getLeafNodeFunction · 0.70
getSiblingNodeFunction · 0.70

Tested by

no test coverage detected