@@ -7,6 +7,7 @@ use crate::{
7
7
} ,
8
8
keys,
9
9
strings:: commands,
10
+ ui:: calc_scroll_top,
10
11
} ;
11
12
use asyncgit:: { sync, AsyncLog , AsyncNotification , CWD } ;
12
13
use crossbeam_channel:: Sender ;
@@ -55,6 +56,7 @@ pub struct Revlog {
55
56
scroll_state : ( Instant , f32 ) ,
56
57
tags : Tags ,
57
58
current_size : ( u16 , u16 ) ,
59
+ scroll_top : usize ,
58
60
}
59
61
60
62
impl Revlog {
@@ -70,6 +72,7 @@ impl Revlog {
70
72
scroll_state : ( Instant :: now ( ) , 0_f32 ) ,
71
73
tags : Tags :: new ( ) ,
72
74
current_size : ( 0 , 0 ) ,
75
+ scroll_top : 0 ,
73
76
}
74
77
}
75
78
@@ -233,22 +236,12 @@ impl Revlog {
233
236
234
237
assert_eq ! ( txt. len( ) - count_before, ELEMENTS_PER_LINE ) ;
235
238
}
236
- }
237
-
238
- impl DrawableComponent for Revlog {
239
- fn draw < B : Backend > ( & mut self , f : & mut Frame < B > , area : Rect ) {
240
- self . current_size = (
241
- area. width . saturating_sub ( 2 ) ,
242
- area. height . saturating_sub ( 2 ) ,
243
- ) ;
244
239
245
- let height = area. height as usize ;
246
- let selection =
247
- self . selection . saturating_sub ( self . items . index_offset ) ;
248
- let height_d2 = height as usize / 2 ;
249
- let min = selection. saturating_sub ( height_d2) ;
240
+ fn get_text ( & self ) -> Vec < Text > {
241
+ let selection = self . relative_selection ( ) ;
250
242
251
243
let mut txt = Vec :: new ( ) ;
244
+
252
245
for ( idx, e) in self . items . items . iter ( ) . enumerate ( ) {
253
246
let tag = if let Some ( tags) = self . tags . get ( & e. hash ) {
254
247
Some ( tags. join ( " " ) )
@@ -258,16 +251,41 @@ impl DrawableComponent for Revlog {
258
251
Self :: add_entry ( e, idx == selection, & mut txt, tag) ;
259
252
}
260
253
254
+ txt
255
+ }
256
+
257
+ fn relative_selection ( & self ) -> usize {
258
+ self . selection . saturating_sub ( self . items . index_offset )
259
+ }
260
+ }
261
+
262
+ impl DrawableComponent for Revlog {
263
+ fn draw < B : Backend > ( & mut self , f : & mut Frame < B > , area : Rect ) {
264
+ self . current_size = (
265
+ area. width . saturating_sub ( 2 ) ,
266
+ area. height . saturating_sub ( 2 ) ,
267
+ ) ;
268
+
269
+ let height_in_lines = self . current_size . 1 as usize ;
270
+ let selection = self . relative_selection ( ) ;
271
+
272
+ self . scroll_top = calc_scroll_top (
273
+ self . scroll_top ,
274
+ height_in_lines,
275
+ selection,
276
+ ) ;
277
+
261
278
let title = format ! (
262
279
"commit {}/{}" ,
263
- self . selection, self . selection_max
280
+ self . selection, self . selection_max,
264
281
) ;
265
282
266
283
f. render_widget (
267
284
Paragraph :: new (
268
- txt. iter ( )
269
- . skip ( min * ELEMENTS_PER_LINE )
270
- . take ( height * ELEMENTS_PER_LINE ) ,
285
+ self . get_text ( )
286
+ . iter ( )
287
+ . skip ( self . scroll_top * ELEMENTS_PER_LINE )
288
+ . take ( height_in_lines * ELEMENTS_PER_LINE ) ,
271
289
)
272
290
. block (
273
291
Block :: default ( )
0 commit comments