1
1
use super :: {
2
- CommandBlocking , Direction , DrawableComponent , ScrollType ,
2
+ utils:: scroll_vertical:: VerticalScroll , CommandBlocking ,
3
+ Direction , DrawableComponent , ScrollType ,
3
4
} ;
4
5
use crate :: {
5
6
components:: { CommandInfo , Component , EventState } ,
6
7
keys:: SharedKeyConfig ,
7
8
queue:: { Action , InternalEvent , NeedsUpdate , Queue , ResetItem } ,
8
9
strings, try_or_popup,
9
- ui:: { self , calc_scroll_top , style:: SharedTheme } ,
10
+ ui:: style:: SharedTheme ,
10
11
} ;
11
12
use anyhow:: Result ;
12
13
use asyncgit:: {
@@ -105,7 +106,7 @@ pub struct DiffComponent {
105
106
current_size : Cell < ( u16 , u16 ) > ,
106
107
focused : bool ,
107
108
current : Current ,
108
- scroll_top : Cell < usize > ,
109
+ scroll : VerticalScroll ,
109
110
queue : Queue ,
110
111
theme : SharedTheme ,
111
112
key_config : SharedKeyConfig ,
@@ -129,7 +130,7 @@ impl DiffComponent {
129
130
diff : None ,
130
131
current_size : Cell :: new ( ( 0 , 0 ) ) ,
131
132
selection : Selection :: Single ( 0 ) ,
132
- scroll_top : Cell :: new ( 0 ) ,
133
+ scroll : VerticalScroll :: new ( ) ,
133
134
theme,
134
135
key_config,
135
136
is_immutable,
@@ -150,7 +151,7 @@ impl DiffComponent {
150
151
pub fn clear ( & mut self , pending : bool ) {
151
152
self . current = Current :: default ( ) ;
152
153
self . diff = None ;
153
- self . scroll_top . set ( 0 ) ;
154
+ self . scroll . reset ( ) ;
154
155
self . selection = Selection :: Single ( 0 ) ;
155
156
self . selected_hunk = None ;
156
157
self . pending = pending;
@@ -178,7 +179,7 @@ impl DiffComponent {
178
179
self . diff = Some ( diff) ;
179
180
180
181
if reset_selection {
181
- self . scroll_top . set ( 0 ) ;
182
+ self . scroll . reset ( ) ;
182
183
self . selection = Selection :: Single ( 0 ) ;
183
184
self . update_selection ( 0 ) ;
184
185
} else {
@@ -336,7 +337,7 @@ impl DiffComponent {
336
337
Span :: raw( Cow :: from( ")" ) ) ,
337
338
] ) ] ) ;
338
339
} else {
339
- let min = self . scroll_top . get ( ) ;
340
+ let min = self . scroll . get ( ) ;
340
341
let max = min + height as usize ;
341
342
342
343
let mut line_cursor = 0_usize ;
@@ -604,11 +605,11 @@ impl DrawableComponent for DiffComponent {
604
605
605
606
let current_height = self . current_size . get ( ) . 1 ;
606
607
607
- self . scroll_top . set ( calc_scroll_top (
608
- self . scroll_top . get ( ) ,
609
- current_height as usize ,
608
+ self . scroll . update (
610
609
self . selection . get_end ( ) ,
611
- ) ) ;
610
+ self . lines_count ( ) ,
611
+ usize:: from ( current_height) ,
612
+ ) ;
612
613
613
614
let title = format ! (
614
615
"{}{}" ,
@@ -637,15 +638,9 @@ impl DrawableComponent for DiffComponent {
637
638
) ,
638
639
r,
639
640
) ;
641
+
640
642
if self . focused {
641
- ui:: draw_scrollbar (
642
- f,
643
- r,
644
- & self . theme ,
645
- self . lines_count ( )
646
- . saturating_sub ( usize:: from ( current_height) ) ,
647
- self . scroll_top . get ( ) ,
648
- ) ;
643
+ self . scroll . draw ( f, r, & self . theme ) ;
649
644
}
650
645
651
646
Ok ( ( ) )
0 commit comments