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

Function getNodeForCharacterOffset

code/third-party/public/app.js:5540–5561  ·  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

5538 * @return {?object}
5539 */
5540function getNodeForCharacterOffset(root, offset) {
5541 var node = getLeafNode(root);
5542 var nodeStart = 0;
5543 var nodeEnd = 0;
5544
5545 while (node) {
5546 if (node.nodeType === TEXT_NODE) {
5547 nodeEnd = nodeStart + node.textContent.length;
5548
5549 if (nodeStart <= offset && nodeEnd >= offset) {
5550 return {
5551 node: node,
5552 offset: offset - nodeStart
5553 };
5554 }
5555
5556 nodeStart = nodeEnd;
5557 }
5558
5559 node = getLeafNode(getSiblingNode(node));
5560 }
5561}
5562
5563/**
5564 * @param {DOMElement} outerNode

Callers 1

setOffsetsFunction · 0.70

Calls 2

getLeafNodeFunction · 0.70
getSiblingNodeFunction · 0.70

Tested by

no test coverage detected