@@ -38,9 +38,14 @@ impl VerticalScroll {
3838 ScrollType :: PageDown => old
3939 . saturating_add ( self . visual_height . get ( ) )
4040 . saturating_sub ( 1 ) ,
41- ScrollType :: PageUp => old
42- . saturating_sub ( self . visual_height . get ( ) )
43- . saturating_add ( 1 ) ,
41+ ScrollType :: PageUp => {
42+ if old < self . visual_height . get ( ) {
43+ 0
44+ } else {
45+ old. saturating_sub ( self . visual_height . get ( ) )
46+ . saturating_add ( 1 )
47+ }
48+ }
4449 ScrollType :: Home => 0 ,
4550 ScrollType :: End => max,
4651 } ;
@@ -201,4 +206,26 @@ mod tests {
201206 scroll. move_area_to_visible ( visual_height, 0 , 2 ) ;
202207 assert_eq ! ( scroll. get_top( ) , 0 ) ;
203208 }
209+
210+ #[ test]
211+ fn test_scroll_with_pageup_pagedown ( ) {
212+ let scroll = VerticalScroll :: new ( ) ;
213+ scroll. max_top . set ( 10 ) ;
214+ scroll. visual_height . set ( 8 ) ;
215+
216+ assert ! ( scroll. move_top( ScrollType :: End ) ) ;
217+ assert_eq ! ( scroll. get_top( ) , 10 ) ;
218+
219+ assert ! ( !scroll. move_top( ScrollType :: PageDown ) ) ;
220+ assert_eq ! ( scroll. get_top( ) , 10 ) ;
221+
222+ assert ! ( scroll. move_top( ScrollType :: PageUp ) ) ;
223+ assert_eq ! ( scroll. get_top( ) , 3 ) ;
224+
225+ assert ! ( scroll. move_top( ScrollType :: PageUp ) ) ;
226+ assert_eq ! ( scroll. get_top( ) , 0 ) ;
227+
228+ assert ! ( !scroll. move_top( ScrollType :: PageUp ) ) ;
229+ assert_eq ! ( scroll. get_top( ) , 0 ) ;
230+ }
204231}
0 commit comments