@@ -40,6 +40,7 @@ pub struct DetailsComponent {
40
40
focused : bool ,
41
41
current_width : Cell < u16 > ,
42
42
scroll : VerticalScroll ,
43
+ scroll_to_bottom_next_draw : Cell < bool > ,
43
44
key_config : SharedKeyConfig ,
44
45
}
45
46
@@ -58,6 +59,7 @@ impl DetailsComponent {
58
59
tags : Vec :: new ( ) ,
59
60
theme,
60
61
focused,
62
+ scroll_to_bottom_next_draw : Cell :: new ( false ) ,
61
63
current_width : Cell :: new ( 0 ) ,
62
64
scroll : VerticalScroll :: new ( ) ,
63
65
key_config,
@@ -318,11 +320,6 @@ impl DrawableComponent for DetailsComponent {
318
320
319
321
self . current_width . set ( width) ;
320
322
321
- let wrapped_lines = self . get_wrapped_text_message (
322
- width as usize ,
323
- height as usize ,
324
- ) ;
325
-
326
323
let number_of_lines =
327
324
Self :: get_number_of_lines ( & self . data , usize:: from ( width) ) ;
328
325
@@ -331,6 +328,11 @@ impl DrawableComponent for DetailsComponent {
331
328
usize:: from ( height) ,
332
329
) ;
333
330
331
+ if self . scroll_to_bottom_next_draw . get ( ) {
332
+ self . scroll . move_top ( ScrollType :: End ) ;
333
+ self . scroll_to_bottom_next_draw . set ( false ) ;
334
+ }
335
+
334
336
let can_scroll = usize:: from ( height) < number_of_lines;
335
337
336
338
f. render_widget (
@@ -346,7 +348,10 @@ impl DrawableComponent for DetailsComponent {
346
348
EMPTY_STRING
347
349
}
348
350
) ,
349
- Text :: from ( wrapped_lines) ,
351
+ Text :: from ( self . get_wrapped_text_message (
352
+ width as usize ,
353
+ height as usize ,
354
+ ) ) ,
350
355
& self . theme ,
351
356
self . focused ,
352
357
) ,
@@ -414,6 +419,12 @@ impl Component for DetailsComponent {
414
419
}
415
420
416
421
fn focus ( & mut self , focus : bool ) {
422
+ if focus {
423
+ self . scroll_to_bottom_next_draw . set ( true ) ;
424
+ } else {
425
+ self . scroll . reset ( ) ;
426
+ }
427
+
417
428
self . focused = focus;
418
429
}
419
430
}
0 commit comments