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

Function posFromMouse

src/codemirror.js:3565–3579  ·  view source on GitHub ↗
(cm, e, liberal, forRect)

Source from the content-addressed store, hash-verified

3563 // selections, and tries to estimate a character position even for
3564 // coordinates beyond the right of the text.
3565 function posFromMouse(cm, e, liberal, forRect) {
3566 var display = cm.display;
3567 if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null;
3568
3569 var x, y, space = display.lineSpace.getBoundingClientRect();
3570 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
3571 try { x = e.clientX - space.left; y = e.clientY - space.top; }
3572 catch (e) { return null; }
3573 var coords = coordsChar(cm, x, y), line;
3574 if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
3575 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
3576 coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
3577 }
3578 return coords;
3579 }
3580
3581 // A mouse down can be a single click, double click, triple click,
3582 // start of selection drag, start of text drag, new cursor

Callers 7

codemirror.jsFile · 0.85
registerEventHandlersFunction · 0.85
onMouseDownFunction · 0.85
leftButtonSelectFunction · 0.85
extendFunction · 0.85
onDropFunction · 0.85
onDragOverFunction · 0.85

Calls 5

e_targetFunction · 0.85
coordsCharFunction · 0.85
getLineFunction · 0.85
paddingHFunction · 0.85
charWidthFunction · 0.85

Tested by

no test coverage detected