MCPcopy
hub / github.com/witheve/Eve / coordsChar

Function coordsChar

src/codemirror.js:2892–2911  ·  view source on GitHub ↗
(cm, x, y)

Source from the content-addressed store, hash-verified

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

Callers 3

posFromMouseFunction · 0.85
findPosVFunction · 0.85
codemirror.jsFile · 0.85

Calls 7

PosWithInfoFunction · 0.85
lineAtHeightFunction · 0.85
getLineFunction · 0.85
coordsCharInnerFunction · 0.85
collapsedSpanAtEndFunction · 0.85
lineNoFunction · 0.85
findMethod · 0.65

Tested by

no test coverage detected