@@ -703,7 +703,7 @@ const Buffer = Module("buffer", {
703
703
* Scrolls to the bottom of the current buffer.
704
704
*/
705
705
scrollBottom : function ( ) {
706
- Buffer . scrollToPercent ( null , 100 ) ;
706
+ Buffer . scrollElemToPercent ( null , null , 100 ) ;
707
707
} ,
708
708
709
709
/**
@@ -720,7 +720,7 @@ const Buffer = Module("buffer", {
720
720
* Scrolls to the top of the current buffer.
721
721
*/
722
722
scrollEnd : function ( ) {
723
- Buffer . scrollToPercent ( 100 , null ) ;
723
+ Buffer . scrollElemToPercent ( null , 100 , null ) ;
724
724
} ,
725
725
726
726
/**
@@ -747,21 +747,19 @@ const Buffer = Module("buffer", {
747
747
* Scrolls the buffer vertically 'scroll' lines.
748
748
*
749
749
* @param {boolean } direction The direction to scroll. If true then
750
- * scroll up and if false scroll down .
750
+ * scroll down and if false scroll up .
751
751
* @param {number } count The multiple of 'scroll' lines to scroll.
752
752
* @optional
753
753
*/
754
754
scrollByScrollSize : function ( direction , count ) {
755
755
direction = direction ? 1 : - 1 ;
756
756
count = count || 1 ;
757
- let win = Buffer . findScrollableWindow ( ) ;
758
-
759
- Buffer . checkScrollYBounds ( win , direction ) ;
757
+ let elem = Buffer . findScrollable ( direction , false ) ;
760
758
761
759
if ( options [ "scroll" ] > 0 )
762
760
this . scrollLines ( options [ "scroll" ] * direction ) ;
763
761
else // scroll half a page down in pixels
764
- win . scrollBy ( 0 , win . innerHeight / 2 * direction ) ;
762
+ elem . scrollTop += Buffer . findScrollableWindow ( ) . innerHeight / 2 * direction ;
765
763
} ,
766
764
767
765
_scrollByScrollSize : function _scrollByScrollSize ( count , direction ) {
@@ -777,7 +775,7 @@ const Buffer = Module("buffer", {
777
775
* @param {number } y The vertical page percentile.
778
776
*/
779
777
scrollToPercent : function ( x , y ) {
780
- Buffer . scrollToPercent ( x , y ) ;
778
+ Buffer . scrollElemToPercent ( null , x , y ) ;
781
779
} ,
782
780
783
781
/**
@@ -795,14 +793,14 @@ const Buffer = Module("buffer", {
795
793
* Scrolls the current buffer laterally to its leftmost.
796
794
*/
797
795
scrollStart : function ( ) {
798
- Buffer . scrollToPercent ( 0 , null ) ;
796
+ Buffer . scrollElemToPercent ( null , 0 , null ) ;
799
797
} ,
800
798
801
799
/**
802
800
* Scrolls the current buffer vertically to the top.
803
801
*/
804
802
scrollTop : function ( ) {
805
- Buffer . scrollToPercent ( null , 0 ) ;
803
+ Buffer . scrollElemToPercent ( null , null , 0 ) ;
806
804
} ,
807
805
808
806
// TODO: allow callback for filtering out unwanted frames? User defined?
@@ -1069,7 +1067,7 @@ const Buffer = Module("buffer", {
1069
1067
return win ;
1070
1068
} ,
1071
1069
1072
- findScrollable : function findScrollable ( dir , horizontal ) {
1070
+ findScrollable : function findScrollable ( dir = 0 , horizontal ) {
1073
1071
let pos = "scrollTop ", maxPos = "scrollTopMax ", clientSize = "clientHeight ";
1074
1072
if ( horizontal )
1075
1073
pos = "scrollLeft ", maxPos = "scrollLeftMax ", clientSize = "clientWidth ";
@@ -1081,7 +1079,7 @@ const Buffer = Module("buffer", {
1081
1079
for ( ; elem && elem . parentNode instanceof Element ; elem = elem . parentNode ) {
1082
1080
if ( elem [ clientSize ] == 0 )
1083
1081
continue ;
1084
- if ( dir < 0 && elem [ pos ] > 0 || dir > 0 && elem [ pos ] < elem [ maxPos ] )
1082
+ if ( dir < 0 && elem [ pos ] > 0 || dir > 0 && elem [ pos ] < elem [ maxPos ] || dir == 0 && elem [ maxPos ] > 0 )
1085
1083
break ;
1086
1084
}
1087
1085
return elem ;
0 commit comments