@@ -981,9 +981,54 @@ cls.JsSourceView = function(id, name, container_class)
981981 }
982982 } ;
983983
984+ var _last_delta = 0 ;
985+ var _accumulated_delta = 0 ;
986+ const UNIT_LINES = 1 ;
987+ const UNIT_PIXELS = 2 ;
988+
989+ this . _get_lines_from_delta = function ( delta , unit )
990+ {
991+ var lines ;
992+ if ( unit == UNIT_LINES )
993+ lines = delta ;
994+ else if ( unit == UNIT_PIXELS )
995+ {
996+ if ( _last_delta * delta < 0 )
997+ // Scroll direction has changed - reset accumulated delta.
998+ _accumulated_delta = 0 ;
999+
1000+ _last_delta = delta ;
1001+ _accumulated_delta += delta ;
1002+ // Convert pixels to lines.
1003+ delta = _accumulated_delta / window . defaults [ "js-source-line-height" ] ;
1004+
1005+ if ( Math . abs ( delta ) >= 1 )
1006+ {
1007+ // Enough delta to scroll at least one line, round delta to
1008+ // integer and store remainder for later.
1009+ lines = delta >= 1 ? Math . floor ( delta ) : Math . ceil ( delta ) ;
1010+ _accumulated_delta = delta % 1 ;
1011+ }
1012+ else
1013+ // Not enough delta accumulated to scroll.
1014+ lines = 0 ;
1015+ }
1016+ else
1017+ lines = 0 ;
1018+
1019+ return lines ;
1020+ }
1021+
9841022 eventHandlers . mousewheel [ 'scroll-js-source-view' ] = function ( event , target )
9851023 {
986- this . _scroll_lines ( ( event . detail > 0 ? 1 : - 1 ) * 3 , event , target ) ;
1024+ if ( event . wheelDeltaX !== undefined && event . wheelDeltaX != 0 )
1025+ // Horizontal scrolling is handled natively by the browser.
1026+ return ;
1027+
1028+ var unit = navigator . platform == 'MacIntel' ? UNIT_PIXELS : UNIT_LINES ;
1029+ var lines = this . _get_lines_from_delta ( - event . wheelDelta / 3 , unit ) ;
1030+ if ( lines )
1031+ this . _scroll_lines ( lines , event , target , unit ) ;
9871032 } . bind ( this ) ;
9881033
9891034 this . _handlers [ 'show-window-go-to-line' ] = function ( event , target )
0 commit comments