marijnh/CodeMirror — pull request #1151 by njx (2013-01-10 20:02:45+00:00)
Title: Make temporary wheel measurement vars per-instance

In order to measure the average pixels-per-wheel-event, CodeMirror uses a number of temporary variables to track the dx/dy of a given wheel event and compare it to the actual distance scrolled. These variables are global to the CodeMirror module, so are shared by all CodeMirror instances, and are referred to asynchronously in a `setTimeout` function.

This causes a problem for Brackets, where we have CodeMirror editors nested inside each other. I believe the issue is that a single throw scroll can cross the boundary between the two editors, causing some wheel events to go to one editor and some to go to the other editor. That makes it so that one editor ends up referring to saved scroll/delta values that were set by another editor, leading to wildly erroneous values for `wheelPixelsPerUnit` (which ends up messing up things like the manual handling of horizontal scrolling).

This patch fixes the problem by storing `wheelDX`, `wheelDY`, `wheelStartX`, and `wheelStartY` on the CM instance instead of in module-global variables. `wheelPixelsPerUnit` and `wheelSamples` are still stored globally, so any instance can add its wheel measurement info to the global average; this doesn't seem to cause any problems since those updates are atomic.