From 535486f2764021949ec3478c14ed1a980d64e9ac Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sat, 5 Jun 2021 23:04:05 +0200 Subject: [PATCH] use new VerticalScroll in diff aswell --- src/components/diff.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/components/diff.rs b/src/components/diff.rs index 53a4f4e2..469bb4a0 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -1,12 +1,13 @@ use super::{ - CommandBlocking, Direction, DrawableComponent, ScrollType, + utils::scroll_vertical::VerticalScroll, CommandBlocking, + Direction, DrawableComponent, ScrollType, }; use crate::{ components::{CommandInfo, Component, EventState}, keys::SharedKeyConfig, queue::{Action, InternalEvent, NeedsUpdate, Queue, ResetItem}, strings, try_or_popup, - ui::{self, calc_scroll_top, style::SharedTheme}, + ui::style::SharedTheme, }; use anyhow::Result; use asyncgit::{ @@ -105,7 +106,7 @@ pub struct DiffComponent { current_size: Cell<(u16, u16)>, focused: bool, current: Current, - scroll_top: Cell, + scroll: VerticalScroll, queue: Queue, theme: SharedTheme, key_config: SharedKeyConfig, @@ -129,7 +130,7 @@ impl DiffComponent { diff: None, current_size: Cell::new((0, 0)), selection: Selection::Single(0), - scroll_top: Cell::new(0), + scroll: VerticalScroll::new(), theme, key_config, is_immutable, @@ -150,7 +151,7 @@ impl DiffComponent { pub fn clear(&mut self, pending: bool) { self.current = Current::default(); self.diff = None; - self.scroll_top.set(0); + self.scroll.reset(); self.selection = Selection::Single(0); self.selected_hunk = None; self.pending = pending; @@ -178,7 +179,7 @@ impl DiffComponent { self.diff = Some(diff); if reset_selection { - self.scroll_top.set(0); + self.scroll.reset(); self.selection = Selection::Single(0); self.update_selection(0); } else { @@ -336,7 +337,7 @@ impl DiffComponent { Span::raw(Cow::from(")")), ])]); } else { - let min = self.scroll_top.get(); + let min = self.scroll.get(); let max = min + height as usize; let mut line_cursor = 0_usize; @@ -604,11 +605,11 @@ impl DrawableComponent for DiffComponent { let current_height = self.current_size.get().1; - self.scroll_top.set(calc_scroll_top( - self.scroll_top.get(), - current_height as usize, + self.scroll.update( self.selection.get_end(), - )); + self.lines_count(), + usize::from(current_height), + ); let title = format!( "{}{}", @@ -637,15 +638,9 @@ impl DrawableComponent for DiffComponent { ), r, ); + if self.focused { - ui::draw_scrollbar( - f, - r, - &self.theme, - self.lines_count() - .saturating_sub(usize::from(current_height)), - self.scroll_top.get(), - ); + self.scroll.draw(f, r, &self.theme); } Ok(())