File tree Expand file tree Collapse file tree 2 files changed +19
-16
lines changed Expand file tree Collapse file tree 2 files changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use crate::{
16
16
use anyhow:: Result ;
17
17
use asyncgit:: { hash, StatusItem , StatusItemType } ;
18
18
use crossterm:: event:: Event ;
19
+ use std:: cell:: Cell ;
19
20
use std:: { borrow:: Cow , convert:: From , path:: Path } ;
20
21
use tui:: { backend:: Backend , layout:: Rect , widgets:: Text , Frame } ;
21
22
@@ -28,6 +29,7 @@ pub struct FileTreeComponent {
28
29
show_selection : bool ,
29
30
queue : Option < Queue > ,
30
31
theme : SharedTheme ,
32
+ scroll_top : Cell < usize > ,
31
33
}
32
34
33
35
impl FileTreeComponent {
@@ -46,6 +48,7 @@ impl FileTreeComponent {
46
48
show_selection : focus,
47
49
queue,
48
50
theme,
51
+ scroll_top : Cell :: new ( 0 ) ,
49
52
}
50
53
}
51
54
@@ -247,12 +250,25 @@ impl DrawableComponent for FileTreeComponent {
247
250
} ,
248
251
) ;
249
252
253
+ let select = self
254
+ . tree
255
+ . selection
256
+ . map ( |idx| idx - selection_offset)
257
+ . unwrap_or_default ( ) ;
258
+ let tree_height = r. height . saturating_sub ( 2 ) as usize ;
259
+
260
+ self . scroll_top . set ( ui:: calc_scroll_top (
261
+ self . scroll_top . get ( ) ,
262
+ tree_height,
263
+ select,
264
+ ) ) ;
265
+
250
266
ui:: draw_list (
251
267
f,
252
268
r,
253
269
self . title . as_str ( ) ,
254
- items,
255
- self . tree . selection . map ( |idx| idx - selection_offset ) ,
270
+ items. skip ( self . scroll_top . get ( ) ) ,
271
+ Some ( select ) ,
256
272
self . focused ,
257
273
& self . theme ,
258
274
) ;
Original file line number Diff line number Diff line change 49
49
L : Iterator < Item = Text < ' b > > ,
50
50
{
51
51
fn render ( self , area : Rect , buf : & mut Buffer ) {
52
- let list_area = match self . block {
53
- Some ( b) => b. inner ( area) ,
54
- None => area,
55
- } ;
56
-
57
- let list_height = list_area. height as usize ;
58
-
59
- let offset = if self . scroll >= list_height {
60
- self . scroll - list_height + 1
61
- } else {
62
- 0
63
- } ;
64
-
65
52
// Render items
66
- List :: new ( self . items . skip ( offset as usize ) )
53
+ List :: new ( self . items )
67
54
. block ( self . block . unwrap_or_default ( ) )
68
55
. style ( self . style )
69
56
. render ( area, buf) ;
You can’t perform that action at this time.
0 commit comments