marijnh/CodeMirror — pull request #2432 by njx (2014-04-03 00:31:12+00:00)
Title: Attempted fix for #2420: re-check line heights after updating doc height/scrollbars

This is an attempt to fix #2420, although I don't know if it's really a good approach.

What seems to be happening is that in some edge cases, when line wrapping is on, `setDocumentHeight()` can cause Chrome (and Safari) to change the wrapping of certain lines, possibly because it's trying to account for native scrollbar width (even though in this case the vertical scrollbar shouldn't appear). It's not entirely clear why this would happen - it might be a bug in WebKit/Blink; #2420 doesn't happen in Firefox.

When that happens, CodeMirror's line heights get out of sync, which causes things like the selection being drawn in the wrong position and mouse event coordinates being interpreted wrong.

This attempts to fix it by re-checking the line heights in the current viewport after the doc height is updated. The weird flickery line-wrapping behavior in #2420 still occurs, but at least CM's mouse handling becomes consistent, which is the main thing we care about.

The main issue with this proposal is that introducing a second call to `updateHeightsInViewport()` might be bad for performance.