@@ -16,7 +16,10 @@ use asyncgit::{
16
16
CWD ,
17
17
} ;
18
18
use crossterm:: event:: Event ;
19
- use std:: { cell:: Cell , convert:: TryInto } ;
19
+ use std:: {
20
+ cell:: Cell ,
21
+ convert:: { TryFrom , TryInto } ,
22
+ } ;
20
23
use tui:: {
21
24
backend:: Backend ,
22
25
layout:: { Alignment , Rect } ,
@@ -35,6 +38,7 @@ pub struct SelectBranchComponent {
35
38
visible : bool ,
36
39
selection : u16 ,
37
40
scroll_top : Cell < usize > ,
41
+ current_height : Cell < u16 > ,
38
42
queue : Queue ,
39
43
theme : SharedTheme ,
40
44
key_config : SharedKeyConfig ,
@@ -92,6 +96,8 @@ impl DrawableComponent for SelectBranchComponent {
92
96
self . branch_names . len ( ) ,
93
97
self . scroll_top . get ( ) ,
94
98
) ;
99
+
100
+ self . current_height . set ( u16:: try_from ( height_in_lines) ?) ;
95
101
}
96
102
97
103
Ok ( ( ) )
@@ -155,6 +161,10 @@ impl Component for SelectBranchComponent {
155
161
return self . move_selection ( ScrollType :: Up ) ;
156
162
} else if e == self . key_config . move_up {
157
163
return self . move_selection ( ScrollType :: Down ) ;
164
+ } else if e == self . key_config . page_down {
165
+ return self . move_selection ( ScrollType :: PageDown ) ;
166
+ } else if e == self . key_config . page_up {
167
+ return self . move_selection ( ScrollType :: PageUp ) ;
158
168
} else if e == self . key_config . enter {
159
169
if let Err ( e) = self . switch_to_selected_branch ( ) {
160
170
log:: error!( "switch branch error: {}" , e) ;
@@ -232,6 +242,7 @@ impl SelectBranchComponent {
232
242
queue,
233
243
theme,
234
244
key_config,
245
+ current_height : Cell :: new ( 0 ) ,
235
246
}
236
247
}
237
248
/// Get all the names of the branches in the repo
@@ -273,6 +284,12 @@ impl SelectBranchComponent {
273
284
let mut new_selection = match scroll {
274
285
ScrollType :: Up => self . selection . saturating_add ( 1 ) ,
275
286
ScrollType :: Down => self . selection . saturating_sub ( 1 ) ,
287
+ ScrollType :: PageDown => self
288
+ . selection
289
+ . saturating_add ( self . current_height . get ( ) ) ,
290
+ ScrollType :: PageUp => self
291
+ . selection
292
+ . saturating_sub ( self . current_height . get ( ) ) ,
276
293
_ => self . selection ,
277
294
} ;
278
295
0 commit comments