@@ -29,6 +29,7 @@ struct Current {
29
29
pub struct DiffComponent {
30
30
diff : FileDiff ,
31
31
scroll : u16 ,
32
+ current_height : u16 ,
32
33
focused : bool ,
33
34
current : Current ,
34
35
selected_hunk : Option < u16 > ,
@@ -45,6 +46,7 @@ impl DiffComponent {
45
46
selected_hunk : None ,
46
47
diff : FileDiff :: default ( ) ,
47
48
scroll : 0 ,
49
+ current_height : 0 ,
48
50
}
49
51
}
50
52
///
@@ -92,21 +94,20 @@ impl DiffComponent {
92
94
93
95
let scroll_max = self . diff . lines . saturating_sub ( 1 ) ;
94
96
95
- match scroll {
96
- ScrollType :: Down => {
97
- self . scroll = cmp:: min (
98
- scroll_max,
99
- self . scroll . saturating_add ( 1 ) ,
100
- ) ;
101
- }
102
- ScrollType :: Up => {
103
- self . scroll = self . scroll . saturating_sub ( 1 ) ;
104
- }
105
- ScrollType :: Home => self . scroll = 0 ,
106
- ScrollType :: End => self . scroll = scroll_max,
107
- ScrollType :: PageDown => ( ) ,
108
- ScrollType :: PageUp => ( ) ,
109
- }
97
+ self . scroll = match scroll {
98
+ ScrollType :: Down => self . scroll . saturating_add ( 1 ) ,
99
+ ScrollType :: Up => self . scroll . saturating_sub ( 1 ) ,
100
+ ScrollType :: Home => 0 ,
101
+ ScrollType :: End => scroll_max,
102
+ ScrollType :: PageDown => self . scroll . saturating_add (
103
+ self . current_height . saturating_sub ( 1 ) ,
104
+ ) ,
105
+ ScrollType :: PageUp => self . scroll . saturating_sub (
106
+ self . current_height . saturating_sub ( 1 ) ,
107
+ ) ,
108
+ } ;
109
+
110
+ self . scroll = cmp:: min ( scroll_max, self . scroll ) ;
110
111
111
112
if old != self . scroll {
112
113
self . selected_hunk =
@@ -297,6 +298,7 @@ impl DiffComponent {
297
298
298
299
impl DrawableComponent for DiffComponent {
299
300
fn draw < B : Backend > ( & mut self , f : & mut Frame < B > , r : Rect ) {
301
+ self . current_height = r. height . saturating_sub ( 2 ) ;
300
302
let mut style_border = Style :: default ( ) . fg ( Color :: DarkGray ) ;
301
303
let mut style_title = Style :: default ( ) ;
302
304
if self . focused {
@@ -368,16 +370,22 @@ impl Component for DiffComponent {
368
370
self . scroll ( ScrollType :: End ) ;
369
371
true
370
372
}
371
-
372
373
keys:: HOME | keys:: SHIFT_UP => {
373
374
self . scroll ( ScrollType :: Home ) ;
374
375
true
375
376
}
376
-
377
377
keys:: MOVE_UP => {
378
378
self . scroll ( ScrollType :: Up ) ;
379
379
true
380
380
}
381
+ keys:: PAGE_UP => {
382
+ self . scroll ( ScrollType :: PageUp ) ;
383
+ true
384
+ }
385
+ keys:: PAGE_DOWN => {
386
+ self . scroll ( ScrollType :: PageDown ) ;
387
+ true
388
+ }
381
389
keys:: ENTER => {
382
390
self . add_hunk ( ) ;
383
391
true
0 commit comments