MCPcopy Create free account
hub / github.com/TruthHun/BookStack / domToPos

Function domToPos

static/editor.md/lib/codemirror/lib/codemirror.js:1793–1810  ·  view source on GitHub ↗
(cm, node, offset)

Source from the content-addressed store, hash-verified

1791 function badPos(pos, bad) { if (bad) pos.bad = true; return pos; }
1792
1793 function domToPos(cm, node, offset) {
1794 var lineNode;
1795 if (node == cm.display.lineDiv) {
1796 lineNode = cm.display.lineDiv.childNodes[offset];
1797 if (!lineNode) return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
1798 node = null; offset = 0;
1799 } else {
1800 for (lineNode = node;; lineNode = lineNode.parentNode) {
1801 if (!lineNode || lineNode == cm.display.lineDiv) return null;
1802 if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) break;
1803 }
1804 }
1805 for (var i = 0; i < cm.display.view.length; i++) {
1806 var lineView = cm.display.view[i];
1807 if (lineView.node == lineNode)
1808 return locateNodeInLineView(lineView, node, offset);
1809 }
1810 }
1811
1812 function locateNodeInLineView(lineView, node, offset) {
1813 var wrapper = lineView.text.firstChild, bad = false;

Callers 1

codemirror.jsFile · 0.70

Calls 2

badPosFunction · 0.70
locateNodeInLineViewFunction · 0.70

Tested by

no test coverage detected