Skip to content

Commit 0355f36

Browse files
committed
extend VerticalScroll::move_top with PageUp and PageDown
1 parent a5d0b47 commit 0355f36

File tree

3 files changed

+15
-38
lines changed

3 files changed

+15
-38
lines changed

src/components/commit_details/details.rs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -247,39 +247,7 @@ impl DetailsComponent {
247247
fn move_scroll_top(&self, move_type: ScrollType) -> bool {
248248
if self.data.is_some() {
249249
let current_height = self.current_size.get().1 as usize;
250-
match move_type {
251-
ScrollType::PageDown => {
252-
let new_top =
253-
self.scroll.get_top().saturating_add(
254-
current_height.saturating_sub(1),
255-
);
256-
if self.scroll.get_top() == new_top {
257-
return false;
258-
}
259-
self.scroll.move_area_to_visible(
260-
current_height,
261-
new_top,
262-
new_top.saturating_add(current_height),
263-
);
264-
true
265-
}
266-
ScrollType::PageUp => {
267-
let new_top =
268-
self.scroll.get_top().saturating_sub(
269-
current_height.saturating_sub(1),
270-
);
271-
if self.scroll.get_top() == new_top {
272-
return false;
273-
}
274-
self.scroll.move_area_to_visible(
275-
current_height,
276-
new_top,
277-
new_top.saturating_add(current_height),
278-
);
279-
true
280-
}
281-
_ => self.scroll.move_top(move_type),
282-
}
250+
self.scroll.move_top(move_type, Some(current_height))
283251
} else {
284252
false
285253
}
@@ -330,7 +298,7 @@ impl DrawableComponent for DetailsComponent {
330298
);
331299

332300
if self.scroll_to_bottom_next_draw.get() {
333-
self.scroll.move_top(ScrollType::End);
301+
self.scroll.move_top(ScrollType::End, None);
334302
self.scroll_to_bottom_next_draw.set(false);
335303
}
336304

src/components/utils/scroll_vertical.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,25 @@ impl VerticalScroll {
2626
self.top.set(0);
2727
}
2828

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

3337
let new_scroll_top = match move_type {
3438
ScrollType::Down => old.saturating_add(1),
3539
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+
),
3646
ScrollType::Home => 0,
3747
ScrollType::End => max,
38-
_ => old,
3948
};
4049

4150
let new_scroll_top = new_scroll_top.clamp(0, max);

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);
144+
self.scroll.move_top(ScrollType::Down, None);
145145
} else if key_match(e, self.key_config.keys.popup_up)
146146
{
147-
self.scroll.move_top(ScrollType::Up);
147+
self.scroll.move_top(ScrollType::Up, None);
148148
}
149149
}
150150
Ok(EventState::Consumed)

0 commit comments

Comments
 (0)