diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index 9c941600..138cc0b6 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -40,6 +40,7 @@ pub struct DetailsComponent { focused: bool, current_width: Cell, scroll: VerticalScroll, + scroll_to_bottom_next_draw: Cell, key_config: SharedKeyConfig, } @@ -58,6 +59,7 @@ impl DetailsComponent { tags: Vec::new(), theme, focused, + scroll_to_bottom_next_draw: Cell::new(false), current_width: Cell::new(0), scroll: VerticalScroll::new(), key_config, @@ -318,11 +320,6 @@ impl DrawableComponent for DetailsComponent { self.current_width.set(width); - let wrapped_lines = self.get_wrapped_text_message( - width as usize, - height as usize, - ); - let number_of_lines = Self::get_number_of_lines(&self.data, usize::from(width)); @@ -331,6 +328,11 @@ impl DrawableComponent for DetailsComponent { usize::from(height), ); + if self.scroll_to_bottom_next_draw.get() { + self.scroll.move_top(ScrollType::End); + self.scroll_to_bottom_next_draw.set(false); + } + let can_scroll = usize::from(height) < number_of_lines; f.render_widget( @@ -346,7 +348,10 @@ impl DrawableComponent for DetailsComponent { EMPTY_STRING } ), - Text::from(wrapped_lines), + Text::from(self.get_wrapped_text_message( + width as usize, + height as usize, + )), &self.theme, self.focused, ), @@ -414,6 +419,12 @@ impl Component for DetailsComponent { } fn focus(&mut self, focus: bool) { + if focus { + self.scroll_to_bottom_next_draw.set(true); + } else { + self.scroll.reset(); + } + self.focused = focus; } } diff --git a/src/components/utils/scroll_vertical.rs b/src/components/utils/scroll_vertical.rs index 883de00d..ed25d79f 100644 --- a/src/components/utils/scroll_vertical.rs +++ b/src/components/utils/scroll_vertical.rs @@ -101,7 +101,7 @@ const fn calc_scroll_top( selection: usize, selection_max: usize, ) -> usize { - if selection_max < height_in_lines { + if selection_max <= height_in_lines { return 0; }