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

Function posFromMouse

static/editor.md/lib/codemirror/lib/codemirror.js:3424–3438  ·  view source on GitHub ↗
(cm, e, liberal, forRect)

Source from the content-addressed store, hash-verified

3422 // selections, and tries to estimate a character position even for
3423 // coordinates beyond the right of the text.
3424 function posFromMouse(cm, e, liberal, forRect) {
3425 var display = cm.display;
3426 if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null;
3427
3428 var x, y, space = display.lineSpace.getBoundingClientRect();
3429 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
3430 try { x = e.clientX - space.left; y = e.clientY - space.top; }
3431 catch (e) { return null; }
3432 var coords = coordsChar(cm, x, y), line;
3433 if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
3434 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
3435 coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
3436 }
3437 return coords;
3438 }
3439
3440 // A mouse down can be a single click, double click, triple click,
3441 // start of selection drag, start of text drag, new cursor

Callers 6

codemirror.jsFile · 0.70
registerEventHandlersFunction · 0.70
onMouseDownFunction · 0.70
leftButtonSelectFunction · 0.70
extendFunction · 0.70
onDropFunction · 0.70

Calls 6

getAttributeMethod · 0.80
e_targetFunction · 0.70
coordsCharFunction · 0.70
getLineFunction · 0.70
paddingHFunction · 0.70
charWidthFunction · 0.70

Tested by

no test coverage detected