MCPcopy
hub / github.com/DHTMLX/gantt / posFromMouse

Function posFromMouse

samples/common/codehighlight/codemirror.js:2957–2971  ·  view source on GitHub ↗
(cm, e, liberal, forRect)

Source from the content-addressed store, hash-verified

2955 // selections, and tries to estimate a character position even for
2956 // coordinates beyond the right of the text.
2957 function posFromMouse(cm, e, liberal, forRect) {
2958 var display = cm.display;
2959 if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
2960
2961 var x, y, space = display.lineSpace.getBoundingClientRect();
2962 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
2963 try { x = e.clientX - space.left; y = e.clientY - space.top; }
2964 catch (e$1) { return null }
2965 var coords = coordsChar(cm, x, y), line;
2966 if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
2967 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
2968 coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
2969 }
2970 return coords
2971 }
2972
2973 // Find the view element corresponding to a given line. Return null
2974 // when the line isn't visible.

Callers 7

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

Calls 7

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

Tested by

no test coverage detected