MCPcopy
hub / github.com/nwutils/nw-sample-apps / posFromMouse

Function posFromMouse

mini-code-edit/cm/lib/codemirror.js:1671–1682  ·  view source on GitHub ↗
(e, liberal)

Source from the content-addressed store, hash-verified

1669 function paddingLeft() {return lineSpace.offsetLeft;}
1670
1671 function posFromMouse(e, liberal) {
1672 var offW = eltOffset(scroller, true), x, y;
1673 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
1674 try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
1675 // This is a mess of a heuristic to try and determine whether a
1676 // scroll-bar was clicked or not, and to return null if one was
1677 // (and !liberal).
1678 if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight))
1679 return null;
1680 var offL = eltOffset(lineSpace, true);
1681 return coordsChar(x - offL.left, y - offL.top);
1682 }
1683 function onContextMenu(e) {
1684 var pos = posFromMouse(e), scrollPos = scroller.scrollTop;
1685 if (!pos || window.opera) return; // Opera is difficult.

Callers 6

onMouseDownFunction · 0.85
extendFunction · 0.85
doneFunction · 0.85
onDoubleClickFunction · 0.85
onDropFunction · 0.85
onContextMenuFunction · 0.85

Calls 2

eltOffsetFunction · 0.85
coordsCharFunction · 0.85

Tested by

no test coverage detected