MCPcopy Create free account
hub / github.com/breck7/scroll / posFromMouse

Function posFromMouse

external/.scrollLibs.js:4391–4414  ·  view source on GitHub ↗
(cm, e, liberal, forRect)

Source from the content-addressed store, hash-verified

4389 // selections, and tries to estimate a character position even for
4390 // coordinates beyond the right of the text.
4391 function posFromMouse(cm, e, liberal, forRect) {
4392 var display = cm.display
4393 if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") {
4394 return null
4395 }
4396
4397 var x,
4398 y,
4399 space = display.lineSpace.getBoundingClientRect()
4400 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
4401 try {
4402 x = e.clientX - space.left
4403 y = e.clientY - space.top
4404 } catch (e) {
4405 return null
4406 }
4407 var coords = coordsChar(cm, x, y),
4408 line
4409 if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
4410 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length
4411 coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff))
4412 }
4413 return coords
4414 }
4415
4416 // Find the view element corresponding to a given line. Return null
4417 // 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
.scrollLibs.jsFile · 0.85

Calls 9

e_targetFunction · 0.85
coordsCharFunction · 0.85
getLineFunction · 0.85
countColumnFunction · 0.85
PosFunction · 0.85
paddingHFunction · 0.85
charWidthFunction · 0.85
getAttributeMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected