Skip to content

Commit 8b76140

Browse files
committed
Use a simpler method for filtering out scrollbar clicks
1 parent ec8c9dc commit 8b76140

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lib/codemirror.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,18 +1103,15 @@ var CodeMirror = (function() {
11031103
function paddingLeft() {return lineSpace.offsetLeft;}
11041104

11051105
function posFromMouse(e, liberal) {
1106-
var off = eltOffset(lineSpace),
1107-
x = e.pageX() - off.left,
1108-
y = e.pageY() - off.top;
1106+
var offW = eltOffset(wrapper), x = e.pageX(), y = e.pageY();
11091107
// This is a mess of a heuristic to try and determine whether a
11101108
// scroll-bar was clicked or not, and to return null if one was
11111109
// (and !liberal).
1112-
if (!liberal && e.target() != lineSpace.parentNode &&
1113-
!(e.target() == wrapper && y > (lines.length * lineHeight()) && wrapper.clientHeight > code.offsetHeight))
1114-
for (var n = e.target(); n != lineDiv && n != cursor; n = n.parentNode)
1115-
if (!n || n == wrapper) return null;
1116-
var line = showingFrom + Math.floor(y / lineHeight());
1117-
return clipPos({line: line, ch: charFromX(clipLine(line), x)});
1110+
if (!liberal && (x - offW.left > wrapper.clientWidth || y - offW.top > wrapper.clientHeight))
1111+
return null;
1112+
var offL = eltOffset(lineSpace);
1113+
var line = showingFrom + Math.floor((y - offL.top) / lineHeight());
1114+
return clipPos({line: line, ch: charFromX(clipLine(line), x - offL.left)});
11181115
}
11191116
function onContextMenu(e) {
11201117
var pos = posFromMouse(e);
@@ -1871,7 +1868,7 @@ var CodeMirror = (function() {
18711868

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

0 commit comments

Comments
 (0)