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

Function coordsChar

static/mergely/lib/codemirror.js:2884–2903  ·  view source on GitHub ↗
(cm, x, y)

Source from the content-addressed store, hash-verified

2882 // Compute the character position closest to the given coordinates.
2883 // Input must be lineSpace-local ("div" coordinate system).
2884 function coordsChar(cm, x, y) {
2885 var doc = cm.doc;
2886 y += cm.display.viewOffset;
2887 if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
2888 var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
2889 if (lineN > last)
2890 return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
2891 if (x < 0) x = 0;
2892
2893 var lineObj = getLine(doc, lineN);
2894 for (;;) {
2895 var found = coordsCharInner(cm, lineObj, lineN, x, y);
2896 var merged = collapsedSpanAtEnd(lineObj);
2897 var mergedPos = merged && merged.find(0, true);
2898 if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
2899 lineN = lineNo(lineObj = mergedPos.to.line);
2900 else
2901 return found;
2902 }
2903 }
2904
2905 function coordsCharInner(cm, lineObj, lineNo, x, y) {
2906 var innerOff = y - heightAtLine(lineObj);

Callers 3

posFromMouseFunction · 0.70
findPosVFunction · 0.70
codemirror.jsFile · 0.70

Calls 6

PosWithInfoFunction · 0.70
lineAtHeightFunction · 0.70
getLineFunction · 0.70
coordsCharInnerFunction · 0.70
collapsedSpanAtEndFunction · 0.70
lineNoFunction · 0.70

Tested by

no test coverage detected