1
1
use super :: {
2
- CommandBlocking , CommandInfo , Component , DrawableComponent ,
3
- EventState , SyntaxTextComponent ,
2
+ utils:: scroll_vertical:: VerticalScroll , CommandBlocking ,
3
+ CommandInfo , Component , DrawableComponent , EventState ,
4
+ SyntaxTextComponent ,
4
5
} ;
5
6
use crate :: {
6
7
keys:: SharedKeyConfig ,
@@ -16,9 +17,7 @@ use asyncgit::{
16
17
use crossbeam_channel:: Sender ;
17
18
use crossterm:: event:: Event ;
18
19
use filetreelist:: { FileTree , FileTreeItem } ;
19
- use std:: {
20
- cell:: Cell , collections:: BTreeSet , convert:: From , path:: Path ,
21
- } ;
20
+ use std:: { collections:: BTreeSet , convert:: From , path:: Path } ;
22
21
use tui:: {
23
22
backend:: Backend ,
24
23
layout:: { Constraint , Direction , Layout , Rect } ,
@@ -43,7 +42,7 @@ pub struct RevisionFilesComponent {
43
42
files : Vec < TreeFile > ,
44
43
current_file : SyntaxTextComponent ,
45
44
tree : FileTree ,
46
- scroll_top : Cell < usize > ,
45
+ scroll : VerticalScroll ,
47
46
revision : Option < CommitId > ,
48
47
focus : Focus ,
49
48
key_config : SharedKeyConfig ,
@@ -60,7 +59,7 @@ impl RevisionFilesComponent {
60
59
Self {
61
60
queue : queue. clone ( ) ,
62
61
tree : FileTree :: default ( ) ,
63
- scroll_top : Cell :: new ( 0 ) ,
62
+ scroll : VerticalScroll :: new ( ) ,
64
63
current_file : SyntaxTextComponent :: new (
65
64
sender,
66
65
key_config. clone ( ) ,
@@ -168,25 +167,22 @@ impl RevisionFilesComponent {
168
167
fn draw_tree < B : Backend > ( & self , f : & mut Frame < B > , area : Rect ) {
169
168
let tree_height = usize:: from ( area. height . saturating_sub ( 2 ) ) ;
170
169
171
- let selection = self . tree . visual_selection ( ) ;
172
- let visual_count = selection. map_or_else (
170
+ self . tree . visual_selection ( ) . map_or_else (
173
171
|| {
174
- self . scroll_top . set ( 0 ) ;
175
- 0
172
+ self . scroll . reset ( ) ;
176
173
} ,
177
174
|selection| {
178
- self . scroll_top . set ( ui:: calc_scroll_top (
179
- self . scroll_top . get ( ) ,
180
- tree_height,
175
+ self . scroll . update (
181
176
selection. index ,
182
- ) ) ;
183
- selection. count
177
+ selection. count ,
178
+ tree_height,
179
+ ) ;
184
180
} ,
185
181
) ;
186
182
187
183
let items = self
188
184
. tree
189
- . iterate ( self . scroll_top . get ( ) , tree_height)
185
+ . iterate ( self . scroll . get ( ) , tree_height)
190
186
. map ( |( item, selected) | {
191
187
Self :: tree_item_to_span ( item, & self . theme , selected)
192
188
} ) ;
@@ -213,13 +209,7 @@ impl RevisionFilesComponent {
213
209
) ;
214
210
215
211
if is_tree_focused {
216
- ui:: draw_scrollbar (
217
- f,
218
- area,
219
- & self . theme ,
220
- visual_count. saturating_sub ( tree_height) ,
221
- self . scroll_top . get ( ) ,
222
- ) ;
212
+ self . scroll . draw ( f, area, & self . theme ) ;
223
213
}
224
214
}
225
215
}
0 commit comments