Skip to content

Commit 9e369e4

Browse files
committed
add VerticalScroll::visual_height
1 parent 0355f36 commit 9e369e4

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/components/commit_details/details.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ impl DetailsComponent {
246246

247247
fn move_scroll_top(&self, move_type: ScrollType) -> bool {
248248
if self.data.is_some() {
249-
let current_height = self.current_size.get().1 as usize;
250-
self.scroll.move_top(move_type, Some(current_height))
249+
self.scroll.move_top(move_type)
251250
} else {
252251
false
253252
}
@@ -286,6 +285,7 @@ impl DrawableComponent for DetailsComponent {
286285
let height = chunks[1].height.saturating_sub(border_width);
287286

288287
self.current_size.set((width, height));
288+
self.scroll.set_visual_height(usize::from(height));
289289

290290
let number_of_lines = Self::get_number_of_lines(
291291
self.data.as_ref(),
@@ -298,7 +298,7 @@ impl DrawableComponent for DetailsComponent {
298298
);
299299

300300
if self.scroll_to_bottom_next_draw.get() {
301-
self.scroll.move_top(ScrollType::End, None);
301+
self.scroll.move_top(ScrollType::End);
302302
self.scroll_to_bottom_next_draw.set(false);
303303
}
304304

src/components/utils/scroll_vertical.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@ use std::cell::Cell;
88
pub struct VerticalScroll {
99
top: Cell<usize>,
1010
max_top: Cell<usize>,
11+
visual_height: Cell<usize>,
1112
}
1213

1314
impl VerticalScroll {
1415
pub const fn new() -> Self {
1516
Self {
1617
top: Cell::new(0),
1718
max_top: Cell::new(0),
19+
visual_height: Cell::new(0),
1820
}
1921
}
2022

23+
pub fn set_visual_height(&self, height: usize) {
24+
self.visual_height.set(height);
25+
}
26+
27+
pub fn get_visual_height(&self) -> usize {
28+
self.visual_height.get()
29+
}
30+
2131
pub fn get_top(&self) -> usize {
2232
self.top.get()
2333
}
@@ -26,23 +36,19 @@ impl VerticalScroll {
2636
self.top.set(0);
2737
}
2838

29-
pub fn move_top(
30-
&self,
31-
move_type: ScrollType,
32-
page_height: Option<usize>,
33-
) -> bool {
39+
pub fn move_top(&self, move_type: ScrollType) -> bool {
3440
let old = self.top.get();
3541
let max = self.max_top.get();
3642

3743
let new_scroll_top = match move_type {
3844
ScrollType::Down => old.saturating_add(1),
3945
ScrollType::Up => old.saturating_sub(1),
40-
ScrollType::PageDown => old.saturating_add(
41-
page_height.unwrap_or(2).saturating_sub(1),
42-
),
43-
ScrollType::PageUp => old.saturating_sub(
44-
page_height.unwrap_or(2).saturating_sub(1),
45-
),
46+
ScrollType::PageDown => old
47+
.saturating_add(self.get_visual_height())
48+
.saturating_sub(1),
49+
ScrollType::PageUp => old
50+
.saturating_sub(self.get_visual_height())
51+
.saturating_add(1),
4652
ScrollType::Home => 0,
4753
ScrollType::End => max,
4854
};

src/popups/msg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ impl Component for MsgPopup {
141141
e,
142142
self.key_config.keys.popup_down,
143143
) {
144-
self.scroll.move_top(ScrollType::Down, None);
144+
self.scroll.move_top(ScrollType::Down);
145145
} else if key_match(e, self.key_config.keys.popup_up)
146146
{
147-
self.scroll.move_top(ScrollType::Up, None);
147+
self.scroll.move_top(ScrollType::Up);
148148
}
149149
}
150150
Ok(EventState::Consumed)

0 commit comments

Comments
 (0)