njx/CodeMirror2 — pull request #3 by njx (2012-03-28 04:16:01+00:00)
Title: Version of flicker-fix that's controllable by an option

@gruehle

Jason and I discovered today that touch scrolling with my flicker-fix code feels bad in Firefox. This is because of the limited resolution provided by Firefox for the mousewheel events that are generated from touch scrolling--as it decelerates, Firefox often ends by reporting nonzero values, which are multiplied by the standard mousewheel delta multiplier, leading to the end of the scroll being jumpy.

I don't think there's a good way to fix this. Conversely, the flickering behavior in the main CodeMirror codebase doesn't seem to happen in Firefox. So, I think the best way to deal with this is to make the flicker-fix version an option that's off by default in Firefox but on everywhere else.

The downside of this is that it complicates the patch somewhat. The upside is that it means that if there are other browsers for which the flicker-fix isn't good, we can easily turn them off in the future as well. It also might make it less scary to merge this into the main CodeMirror codebase, since it makes the new code easy to identify and turn off.

The main change compared to the previous flicker-fix is that we have a new var, vScrollElt, that is set to "scrollbar" when the flickerFix option is on and "scroller" when it's off, so we can just use this everywhere where the scrollTop or scrollHeight needs to be accessed, regardless of how the option is set. Additionally, most of the flicker-fix-related code is guarded by the option. The only behavioral difference in the non-flicker-fix case is that updateVerticalScroll() (which adjusts the scroll height) gets called more often than the analogous code did in the original codebase, and code.style.top gets set more often (but generally to the same value, so it should be a no-op). If we're concerned about this, we could guard these too.