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

Function domToPos

static/mergely/lib/codemirror.js:1889–1906  ·  view source on GitHub ↗
(cm, node, offset)

Source from the content-addressed store, hash-verified

1887 function badPos(pos, bad) { if (bad) pos.bad = true; return pos; }
1888
1889 function domToPos(cm, node, offset) {
1890 var lineNode;
1891 if (node == cm.display.lineDiv) {
1892 lineNode = cm.display.lineDiv.childNodes[offset];
1893 if (!lineNode) return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
1894 node = null; offset = 0;
1895 } else {
1896 for (lineNode = node;; lineNode = lineNode.parentNode) {
1897 if (!lineNode || lineNode == cm.display.lineDiv) return null;
1898 if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) break;
1899 }
1900 }
1901 for (var i = 0; i < cm.display.view.length; i++) {
1902 var lineView = cm.display.view[i];
1903 if (lineView.node == lineNode)
1904 return locateNodeInLineView(lineView, node, offset);
1905 }
1906 }
1907
1908 function locateNodeInLineView(lineView, node, offset) {
1909 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