Skip to content

Commit

Permalink
Use a simpler method for filtering out scrollbar clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed May 9, 2011
1 parent ec8c9dc commit 8b76140
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,18 +1103,15 @@ var CodeMirror = (function() {
function paddingLeft() {return lineSpace.offsetLeft;}

function posFromMouse(e, liberal) {
var off = eltOffset(lineSpace),
x = e.pageX() - off.left,
y = e.pageY() - off.top;
var offW = eltOffset(wrapper), x = e.pageX(), y = e.pageY();
// This is a mess of a heuristic to try and determine whether a
// scroll-bar was clicked or not, and to return null if one was
// (and !liberal).
if (!liberal && e.target() != lineSpace.parentNode &&
!(e.target() == wrapper && y > (lines.length * lineHeight()) && wrapper.clientHeight > code.offsetHeight))
for (var n = e.target(); n != lineDiv && n != cursor; n = n.parentNode)
if (!n || n == wrapper) return null;
var line = showingFrom + Math.floor(y / lineHeight());
return clipPos({line: line, ch: charFromX(clipLine(line), x)});
if (!liberal && (x - offW.left > wrapper.clientWidth || y - offW.top > wrapper.clientHeight))
return null;
var offL = eltOffset(lineSpace);
var line = showingFrom + Math.floor((y - offL.top) / lineHeight());
return clipPos({line: line, ch: charFromX(clipLine(line), x - offL.left)});
}
function onContextMenu(e) {
var pos = posFromMouse(e);
Expand Down Expand Up @@ -1871,7 +1868,7 @@ var CodeMirror = (function() {

// Find the position of an element by following the offsetParent chain.
function eltOffset(node) {
var x = 0, y = 0, n2 = node;
var x = 0, y = 0;
for (var n = node; n; n = n.offsetParent) {x += n.offsetLeft; y += n.offsetTop;}
for (var n = node; n != document.body; n = n.parentNode) {x -= n.scrollLeft; y -= n.scrollTop;}
return {left: x, top: y};
Expand Down

0 comments on commit 8b76140

Please sign in to comment.