Skip to content

Commit

Permalink
Make temporary wheel measurement vars per-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Narciso Jaramillo authored and marijnh committed Jan 11, 2013
1 parent d8009de commit ece10c7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ window.CodeMirror = (function() {
// is that it gives us a chance to update the display before the
// actual scrolling happens, reducing flickering.

var wheelSamples = 0, wheelDX, wheelDY, wheelStartX, wheelStartY, wheelPixelsPerUnit = null;
var wheelSamples = 0, wheelPixelsPerUnit = null;
// Fill in a browser-detected starting value on browsers where we
// know one. These don't have to be accurate -- the result of them
// being wrong would just be a slight flicker on the first wheel
Expand Down Expand Up @@ -1678,7 +1678,7 @@ window.CodeMirror = (function() {
setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
e_preventDefault(e);
wheelStartX = null; // Abort measurement, if in progress
cm.wheelStartX = null; // Abort measurement, if in progress
return;
}

Expand All @@ -1691,22 +1691,22 @@ window.CodeMirror = (function() {
}

if (wheelSamples < 20) {
if (wheelStartX == null) {
wheelStartX = scroll.scrollLeft; wheelStartY = scroll.scrollTop;
wheelDX = dx; wheelDY = dy;
if (cm.wheelStartX == null) {
cm.wheelStartX = scroll.scrollLeft; cm.wheelStartY = scroll.scrollTop;
cm.wheelDX = dx; cm.wheelDY = dy;
setTimeout(function() {
if (wheelStartX == null) return;
var movedX = scroll.scrollLeft - wheelStartX;
var movedY = scroll.scrollTop - wheelStartY;
var sample = (movedY && wheelDY && movedY / wheelDY) ||
(movedX && wheelDX && movedX / wheelDX);
wheelStartX = wheelStartY = null;
if (cm.wheelStartX == null) return;
var movedX = scroll.scrollLeft - cm.wheelStartX;
var movedY = scroll.scrollTop - cm.wheelStartY;
var sample = (movedY && cm.wheelDY && movedY / cm.wheelDY) ||
(movedX && cm.wheelDX && movedX / cm.wheelDX);
cm.wheelStartX = cm.wheelStartY = null;
if (!sample) return;
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
++wheelSamples;
}, 200);
} else {
wheelDX += dx; wheelDY += dy;
cm.wheelDX += dx; cm.wheelDY += dy;
}
}
}
Expand Down

0 comments on commit ece10c7

Please sign in to comment.