@@ -40,6 +40,7 @@ pub struct DetailsComponent {
4040 focused : bool ,
4141 current_width : Cell < u16 > ,
4242 scroll : VerticalScroll ,
43+ scroll_to_bottom_next_draw : Cell < bool > ,
4344 key_config : SharedKeyConfig ,
4445}
4546
@@ -58,6 +59,7 @@ impl DetailsComponent {
5859 tags : Vec :: new ( ) ,
5960 theme,
6061 focused,
62+ scroll_to_bottom_next_draw : Cell :: new ( false ) ,
6163 current_width : Cell :: new ( 0 ) ,
6264 scroll : VerticalScroll :: new ( ) ,
6365 key_config,
@@ -318,11 +320,6 @@ impl DrawableComponent for DetailsComponent {
318320
319321 self . current_width . set ( width) ;
320322
321- let wrapped_lines = self . get_wrapped_text_message (
322- width as usize ,
323- height as usize ,
324- ) ;
325-
326323 let number_of_lines =
327324 Self :: get_number_of_lines ( & self . data , usize:: from ( width) ) ;
328325
@@ -331,6 +328,11 @@ impl DrawableComponent for DetailsComponent {
331328 usize:: from ( height) ,
332329 ) ;
333330
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+
334336 let can_scroll = usize:: from ( height) < number_of_lines;
335337
336338 f. render_widget (
@@ -346,7 +348,10 @@ impl DrawableComponent for DetailsComponent {
346348 EMPTY_STRING
347349 }
348350 ) ,
349- Text :: from ( wrapped_lines) ,
351+ Text :: from ( self . get_wrapped_text_message (
352+ width as usize ,
353+ height as usize ,
354+ ) ) ,
350355 & self . theme ,
351356 self . focused ,
352357 ) ,
@@ -414,6 +419,12 @@ impl Component for DetailsComponent {
414419 }
415420
416421 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+
417428 self . focused = focus;
418429 }
419430}
0 commit comments