@@ -172,6 +172,72 @@ impl RevisionFilesComponent {
172
172
self . current_file . clear ( ) ;
173
173
}
174
174
}
175
+
176
+ fn draw_tree < B : Backend > (
177
+ & self ,
178
+ f : & mut Frame < B > ,
179
+ area : Rect ,
180
+ ) -> Result < ( ) > {
181
+ let tree_height = usize:: from ( area. height . saturating_sub ( 2 ) ) ;
182
+
183
+ let selection = self . tree . visual_selection ( ) ;
184
+ let visual_count = selection. map_or_else (
185
+ || {
186
+ self . scroll_top . set ( 0 ) ;
187
+ 0
188
+ } ,
189
+ |selection| {
190
+ self . scroll_top . set ( ui:: calc_scroll_top (
191
+ self . scroll_top . get ( ) ,
192
+ tree_height,
193
+ selection. index ,
194
+ ) ) ;
195
+ selection. count
196
+ } ,
197
+ ) ;
198
+
199
+ let items = self
200
+ . tree
201
+ . iterate ( self . scroll_top . get ( ) , tree_height)
202
+ . map ( |( item, selected) | {
203
+ Self :: tree_item_to_span ( item, & self . theme , selected)
204
+ } ) ;
205
+
206
+ f. render_widget ( Clear , area) ;
207
+ f. render_widget (
208
+ Block :: default ( )
209
+ . borders ( Borders :: TOP )
210
+ . title ( Span :: styled (
211
+ format ! ( " {}" , self . title) ,
212
+ self . theme . title ( true ) ,
213
+ ) )
214
+ . border_style ( self . theme . block ( true ) ) ,
215
+ area,
216
+ ) ;
217
+
218
+ let is_tree_focused = matches ! ( self . focus, Focus :: Tree ) ;
219
+
220
+ ui:: draw_list_block (
221
+ f,
222
+ area,
223
+ Block :: default ( )
224
+ . borders ( Borders :: ALL )
225
+ . border_style ( self . theme . block ( is_tree_focused) ) ,
226
+ items,
227
+ ) ;
228
+
229
+ if is_tree_focused {
230
+ ui:: draw_scrollbar (
231
+ f,
232
+ area,
233
+ & self . theme ,
234
+ visual_count. saturating_sub ( tree_height) ,
235
+ self . scroll_top . get ( ) ,
236
+ ) ;
237
+ }
238
+
239
+ Ok ( ( ) )
240
+ }
175
241
}
176
242
177
243
impl DrawableComponent for RevisionFilesComponent {
@@ -193,68 +259,7 @@ impl DrawableComponent for RevisionFilesComponent {
193
259
)
194
260
. split ( area) ;
195
261
196
- let tree_height =
197
- usize:: from ( chunks[ 0 ] . height . saturating_sub ( 2 ) ) ;
198
-
199
- let selection = self . tree . visual_selection ( ) ;
200
- let visual_count = selection. map_or_else (
201
- || {
202
- self . scroll_top . set ( 0 ) ;
203
- 0
204
- } ,
205
- |selection| {
206
- self . scroll_top . set ( ui:: calc_scroll_top (
207
- self . scroll_top . get ( ) ,
208
- tree_height,
209
- selection. index ,
210
- ) ) ;
211
- selection. count
212
- } ,
213
- ) ;
214
-
215
- let items = self
216
- . tree
217
- . iterate ( self . scroll_top . get ( ) , tree_height)
218
- . map ( |( item, selected) | {
219
- Self :: tree_item_to_span (
220
- item,
221
- & self . theme ,
222
- selected,
223
- )
224
- } ) ;
225
-
226
- f. render_widget ( Clear , area) ;
227
- f. render_widget (
228
- Block :: default ( )
229
- . borders ( Borders :: TOP )
230
- . title ( Span :: styled (
231
- format ! ( " {}" , self . title) ,
232
- self . theme . title ( true ) ,
233
- ) )
234
- . border_style ( self . theme . block ( true ) ) ,
235
- area,
236
- ) ;
237
-
238
- let is_tree_focused = matches ! ( self . focus, Focus :: Tree ) ;
239
-
240
- ui:: draw_list_block (
241
- f,
242
- chunks[ 0 ] ,
243
- Block :: default ( )
244
- . borders ( Borders :: ALL )
245
- . border_style ( self . theme . block ( is_tree_focused) ) ,
246
- items,
247
- ) ;
248
-
249
- if is_tree_focused {
250
- ui:: draw_scrollbar (
251
- f,
252
- chunks[ 0 ] ,
253
- & self . theme ,
254
- visual_count. saturating_sub ( tree_height) ,
255
- self . scroll_top . get ( ) ,
256
- ) ;
257
- }
262
+ self . draw_tree ( f, chunks[ 0 ] ) ?;
258
263
259
264
self . current_file . draw ( f, chunks[ 1 ] ) ?;
260
265
}
0 commit comments