From 5e62217928a67f773e1346ac622cfbc96692ca92 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Thu, 10 Jun 2021 09:56:20 +0200 Subject: [PATCH] fix commit msg details lockin (#780) --- src/components/branchlist.rs | 2 +- src/components/revision_files.rs | 27 +++++++++++++------------ src/components/utils/scroll_vertical.rs | 16 +++++++++++++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 9b368407..2240743b 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -51,7 +51,7 @@ impl DrawableComponent for BranchListComponent { f: &mut Frame, rect: Rect, ) -> Result<()> { - if self.visible { + if self.is_visible() { const PERCENT_SIZE: Size = Size::new(80, 50); const MIN_SIZE: Size = Size::new(60, 20); diff --git a/src/components/revision_files.rs b/src/components/revision_files.rs index 8266509b..85846984 100644 --- a/src/components/revision_files.rs +++ b/src/components/revision_files.rs @@ -218,21 +218,22 @@ impl DrawableComponent for RevisionFilesComponent { f: &mut Frame, area: Rect, ) -> Result<()> { - let chunks = Layout::default() - .direction(Direction::Horizontal) - .constraints( - [ - Constraint::Percentage(40), - Constraint::Percentage(60), - ] - .as_ref(), - ) - .split(area); + if self.is_visible() { + let chunks = Layout::default() + .direction(Direction::Horizontal) + .constraints( + [ + Constraint::Percentage(40), + Constraint::Percentage(60), + ] + .as_ref(), + ) + .split(area); - self.draw_tree(f, chunks[0]); - - self.current_file.draw(f, chunks[1])?; + self.draw_tree(f, chunks[0]); + self.current_file.draw(f, chunks[1])?; + } Ok(()) } } diff --git a/src/components/utils/scroll_vertical.rs b/src/components/utils/scroll_vertical.rs index ed25d79f..e47d77a4 100644 --- a/src/components/utils/scroll_vertical.rs +++ b/src/components/utils/scroll_vertical.rs @@ -65,8 +65,12 @@ impl VerticalScroll { ); self.top.set(new_top); - let new_max = selection_max.saturating_sub(visual_height); - self.max_top.set(new_max); + if visual_height == 0 { + self.max_top.set(0); + } else { + let new_max = selection_max.saturating_sub(visual_height); + self.max_top.set(new_max); + } new_top } @@ -101,6 +105,9 @@ const fn calc_scroll_top( selection: usize, selection_max: usize, ) -> usize { + if height_in_lines == 0 { + return 0; + } if selection_max <= height_in_lines { return 0; } @@ -123,4 +130,9 @@ mod tests { fn test_scroll_no_scroll_to_top() { assert_eq!(calc_scroll_top(1, 10, 4, 4), 0); } + + #[test] + fn test_scroll_zero_height() { + assert_eq!(calc_scroll_top(4, 0, 4, 3), 0); + } }