MCPcopy Index your code
hub / github.com/csev/py4e / posFromMouse

Function posFromMouse

tools/pythonauto/static/codemirrorepl/codemirror.js:2469–2486  ·  view source on GitHub ↗
(cm, e, liberal, forRect)

Source from the content-addressed store, hash-verified

2467 // selections, and tries to estimate a character position even for
2468 // coordinates beyond the right of the text.
2469 function posFromMouse(cm, e, liberal, forRect) {
2470 var display = cm.display;
2471 if (!liberal) {
2472 var target = e_target(e);
2473 if (target == display.scrollbarH || target == display.scrollbarV ||
2474 target == display.scrollbarFiller || target == display.gutterFiller) return null;
2475 }
2476 var x, y, space = display.lineSpace.getBoundingClientRect();
2477 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
2478 try { x = e.clientX - space.left; y = e.clientY - space.top; }
2479 catch (e) { return null; }
2480 var coords = coordsChar(cm, x, y), line;
2481 if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
2482 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
2483 coords = Pos(coords.line, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff);
2484 }
2485 return coords;
2486 }
2487
2488 // A mouse down can be a single click, double click, triple click,
2489 // start of selection drag, start of text drag, new cursor

Callers 6

registerEventHandlersFunction · 0.70
onMouseDownFunction · 0.70
leftButtonSelectFunction · 0.70
extendFunction · 0.70
onDropFunction · 0.70
onContextMenuFunction · 0.70

Calls 7

PosFunction · 0.85
e_targetFunction · 0.70
coordsCharFunction · 0.70
getLineFunction · 0.70
countColumnFunction · 0.70
paddingHFunction · 0.70
charWidthFunction · 0.70

Tested by

no test coverage detected