Skip to content

Commit 535486f

Browse files
author
Stephan Dilly
committed
use new VerticalScroll in diff aswell
1 parent 3a849bc commit 535486f

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/components/diff.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use super::{
2-
CommandBlocking, Direction, DrawableComponent, ScrollType,
2+
utils::scroll_vertical::VerticalScroll, CommandBlocking,
3+
Direction, DrawableComponent, ScrollType,
34
};
45
use crate::{
56
components::{CommandInfo, Component, EventState},
67
keys::SharedKeyConfig,
78
queue::{Action, InternalEvent, NeedsUpdate, Queue, ResetItem},
89
strings, try_or_popup,
9-
ui::{self, calc_scroll_top, style::SharedTheme},
10+
ui::style::SharedTheme,
1011
};
1112
use anyhow::Result;
1213
use asyncgit::{
@@ -105,7 +106,7 @@ pub struct DiffComponent {
105106
current_size: Cell<(u16, u16)>,
106107
focused: bool,
107108
current: Current,
108-
scroll_top: Cell<usize>,
109+
scroll: VerticalScroll,
109110
queue: Queue,
110111
theme: SharedTheme,
111112
key_config: SharedKeyConfig,
@@ -129,7 +130,7 @@ impl DiffComponent {
129130
diff: None,
130131
current_size: Cell::new((0, 0)),
131132
selection: Selection::Single(0),
132-
scroll_top: Cell::new(0),
133+
scroll: VerticalScroll::new(),
133134
theme,
134135
key_config,
135136
is_immutable,
@@ -150,7 +151,7 @@ impl DiffComponent {
150151
pub fn clear(&mut self, pending: bool) {
151152
self.current = Current::default();
152153
self.diff = None;
153-
self.scroll_top.set(0);
154+
self.scroll.reset();
154155
self.selection = Selection::Single(0);
155156
self.selected_hunk = None;
156157
self.pending = pending;
@@ -178,7 +179,7 @@ impl DiffComponent {
178179
self.diff = Some(diff);
179180

180181
if reset_selection {
181-
self.scroll_top.set(0);
182+
self.scroll.reset();
182183
self.selection = Selection::Single(0);
183184
self.update_selection(0);
184185
} else {
@@ -336,7 +337,7 @@ impl DiffComponent {
336337
Span::raw(Cow::from(")")),
337338
])]);
338339
} else {
339-
let min = self.scroll_top.get();
340+
let min = self.scroll.get();
340341
let max = min + height as usize;
341342

342343
let mut line_cursor = 0_usize;
@@ -604,11 +605,11 @@ impl DrawableComponent for DiffComponent {
604605

605606
let current_height = self.current_size.get().1;
606607

607-
self.scroll_top.set(calc_scroll_top(
608-
self.scroll_top.get(),
609-
current_height as usize,
608+
self.scroll.update(
610609
self.selection.get_end(),
611-
));
610+
self.lines_count(),
611+
usize::from(current_height),
612+
);
612613

613614
let title = format!(
614615
"{}{}",
@@ -637,15 +638,9 @@ impl DrawableComponent for DiffComponent {
637638
),
638639
r,
639640
);
641+
640642
if self.focused {
641-
ui::draw_scrollbar(
642-
f,
643-
r,
644-
&self.theme,
645-
self.lines_count()
646-
.saturating_sub(usize::from(current_height)),
647-
self.scroll_top.get(),
648-
);
643+
self.scroll.draw(f, r, &self.theme);
649644
}
650645

651646
Ok(())

0 commit comments

Comments
 (0)