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

Function coordsChar

static/editor.md/lib/codemirror/lib/codemirror.js:2778–2797  ·  view source on GitHub ↗
(cm, x, y)

Source from the content-addressed store, hash-verified

2776 // Compute the character position closest to the given coordinates.
2777 // Input must be lineSpace-local ("div" coordinate system).
2778 function coordsChar(cm, x, y) {
2779 var doc = cm.doc;
2780 y += cm.display.viewOffset;
2781 if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
2782 var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
2783 if (lineN > last)
2784 return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
2785 if (x < 0) x = 0;
2786
2787 var lineObj = getLine(doc, lineN);
2788 for (;;) {
2789 var found = coordsCharInner(cm, lineObj, lineN, x, y);
2790 var merged = collapsedSpanAtEnd(lineObj);
2791 var mergedPos = merged && merged.find(0, true);
2792 if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
2793 lineN = lineNo(lineObj = mergedPos.to.line);
2794 else
2795 return found;
2796 }
2797 }
2798
2799 function coordsCharInner(cm, lineObj, lineNo, x, y) {
2800 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