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

Function posFromMouse

static/mergely/lib/codemirror.js:3544–3558  ·  view source on GitHub ↗
(cm, e, liberal, forRect)

Source from the content-addressed store, hash-verified

3542 // selections, and tries to estimate a character position even for
3543 // coordinates beyond the right of the text.
3544 function posFromMouse(cm, e, liberal, forRect) {
3545 var display = cm.display;
3546 if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null;
3547
3548 var x, y, space = display.lineSpace.getBoundingClientRect();
3549 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
3550 try { x = e.clientX - space.left; y = e.clientY - space.top; }
3551 catch (e) { return null; }
3552 var coords = coordsChar(cm, x, y), line;
3553 if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
3554 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
3555 coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
3556 }
3557 return coords;
3558 }
3559
3560 // A mouse down can be a single click, double click, triple click,
3561 // start of selection drag, start of text drag, new cursor

Callers 7

codemirror.jsFile · 0.70
registerEventHandlersFunction · 0.70
onMouseDownFunction · 0.70
leftButtonSelectFunction · 0.70
extendFunction · 0.70
onDropFunction · 0.70
onDragOverFunction · 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