@@ -166,6 +166,9 @@ window.CodeMirror = (function() {
166166 // detected
167167 d . pasteIncoming = false ;
168168
169+ // Used for measuring wheel scrolling granularity
170+ d . wheelDX = d . wheelDY = d . wheelStartX = d . wheelStartY = null ;
171+
169172 return d ;
170173 }
171174
@@ -1666,7 +1669,7 @@ window.CodeMirror = (function() {
16661669 }
16671670 }
16681671
1669- var scroll = cm . display . scroller ;
1672+ var display = cm . display , scroll = display . scroller ;
16701673 // On some browsers, horizontal scrolling will cause redraws to
16711674 // happen before the gutter has been realigned, causing it to
16721675 // wriggle around in a most unseemly way. When we have an
@@ -1678,35 +1681,35 @@ window.CodeMirror = (function() {
16781681 setScrollTop ( cm , Math . max ( 0 , Math . min ( scroll . scrollTop + dy * wheelPixelsPerUnit , scroll . scrollHeight - scroll . clientHeight ) ) ) ;
16791682 setScrollLeft ( cm , Math . max ( 0 , Math . min ( scroll . scrollLeft + dx * wheelPixelsPerUnit , scroll . scrollWidth - scroll . clientWidth ) ) ) ;
16801683 e_preventDefault ( e ) ;
1681- cm . wheelStartX = null ; // Abort measurement, if in progress
1684+ display . wheelStartX = null ; // Abort measurement, if in progress
16821685 return ;
16831686 }
16841687
16851688 if ( dy && wheelPixelsPerUnit != null ) {
16861689 var pixels = dy * wheelPixelsPerUnit ;
1687- var top = cm . view . scrollTop , bot = top + cm . display . wrapper . clientHeight ;
1690+ var top = cm . view . scrollTop , bot = top + display . wrapper . clientHeight ;
16881691 if ( pixels < 0 ) top = Math . max ( 0 , top + pixels - 50 ) ;
16891692 else bot = Math . min ( cm . view . doc . height , bot + pixels + 50 ) ;
16901693 updateDisplay ( cm , [ ] , { top : top , bottom : bot } ) ;
16911694 }
16921695
16931696 if ( wheelSamples < 20 ) {
1694- if ( cm . wheelStartX == null ) {
1695- cm . wheelStartX = scroll . scrollLeft ; cm . wheelStartY = scroll . scrollTop ;
1696- cm . wheelDX = dx ; cm . wheelDY = dy ;
1697+ if ( display . wheelStartX == null ) {
1698+ display . wheelStartX = scroll . scrollLeft ; display . wheelStartY = scroll . scrollTop ;
1699+ display . wheelDX = dx ; display . wheelDY = dy ;
16971700 setTimeout ( function ( ) {
1698- if ( cm . wheelStartX == null ) return ;
1699- var movedX = scroll . scrollLeft - cm . wheelStartX ;
1700- var movedY = scroll . scrollTop - cm . wheelStartY ;
1701- var sample = ( movedY && cm . wheelDY && movedY / cm . wheelDY ) ||
1702- ( movedX && cm . wheelDX && movedX / cm . wheelDX ) ;
1703- cm . wheelStartX = cm . wheelStartY = null ;
1701+ if ( display . wheelStartX == null ) return ;
1702+ var movedX = scroll . scrollLeft - display . wheelStartX ;
1703+ var movedY = scroll . scrollTop - display . wheelStartY ;
1704+ var sample = ( movedY && display . wheelDY && movedY / display . wheelDY ) ||
1705+ ( movedX && display . wheelDX && movedX / display . wheelDX ) ;
1706+ display . wheelStartX = display . wheelStartY = null ;
17041707 if ( ! sample ) return ;
17051708 wheelPixelsPerUnit = ( wheelPixelsPerUnit * wheelSamples + sample ) / ( wheelSamples + 1 ) ;
17061709 ++ wheelSamples ;
17071710 } , 200 ) ;
17081711 } else {
1709- cm . wheelDX += dx ; cm . wheelDY += dy ;
1712+ display . wheelDX += dx ; display . wheelDY += dy ;
17101713 }
17111714 }
17121715 }
0 commit comments