@@ -354,8 +354,14 @@ impl FileRevlogComponent {
354
354
}
355
355
356
356
fn set_selection ( & mut self , selection : usize ) {
357
- let height_in_items = self . current_height . get ( ) / 2 ;
358
- let new_offset = selection. saturating_sub ( height_in_items) ;
357
+ let height_in_items =
358
+ ( self . current_height . get ( ) . saturating_sub ( 2 ) ) / 2 ;
359
+
360
+ let offset = * self . table_state . get_mut ( ) . offset_mut ( ) ;
361
+ let min_offset = selection
362
+ . saturating_sub ( height_in_items. saturating_sub ( 1 ) ) ;
363
+
364
+ let new_offset = offset. clamp ( min_offset, selection) ;
359
365
360
366
* self . table_state . get_mut ( ) . offset_mut ( ) = new_offset;
361
367
self . table_state . get_mut ( ) . select ( Some ( selection) ) ;
@@ -364,13 +370,14 @@ impl FileRevlogComponent {
364
370
fn fetch_commits_if_needed ( & mut self ) -> Result < ( ) > {
365
371
let selection =
366
372
self . table_state . get_mut ( ) . selected ( ) . unwrap_or ( 0 ) ;
367
- let height_in_items = self . current_height . get ( ) / 2 ;
368
- let new_offset = selection. saturating_sub ( height_in_items) ;
373
+ let offset = * self . table_state . get_mut ( ) . offset_mut ( ) ;
374
+ let height_in_items =
375
+ ( self . current_height . get ( ) . saturating_sub ( 2 ) ) / 2 ;
369
376
let new_max_offset =
370
377
selection. saturating_add ( height_in_items) ;
371
378
372
- if self . items . needs_data ( new_offset , new_max_offset) {
373
- self . fetch_commits ( new_offset , new_max_offset) ?;
379
+ if self . items . needs_data ( offset , new_max_offset) {
380
+ self . fetch_commits ( offset , new_max_offset) ?;
374
381
}
375
382
376
383
Ok ( ( ) )
@@ -425,7 +432,11 @@ impl FileRevlogComponent {
425
432
. with_selected ( table_state. selected ( ) . map ( |selected| {
426
433
selected. saturating_sub ( self . items . index_offset ( ) )
427
434
} ) )
428
- . with_offset ( 0 ) ;
435
+ . with_offset (
436
+ table_state
437
+ . offset ( )
438
+ . saturating_sub ( self . items . index_offset ( ) ) ,
439
+ ) ;
429
440
430
441
f. render_widget ( Clear , area) ;
431
442
f. render_stateful_widget (
0 commit comments