Skip to content

Commit eb48b37

Browse files
xlai89extrawurst
andauthored
feat: message tab supports pageup and pagedown (#2623) (#2730)
Co-authored-by: extrawurst <776816+extrawurst@users.noreply.github.com>
1 parent 7674dae commit eb48b37

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
* increase MSRV from 1.81 to 1.82 [[@cruessler](https://github.com/cruessler)]
1111

1212
### Added
13+
* Message tab supports pageUp and pageDown [[@xlai89](https://github.com/xlai89)] ([#2623](https://github.com/extrawurst/gitui/issues/2623))
1314
* Files and status tab support pageUp and pageDown [[@fatpandac](https://github.com/fatpandac)] ([#1951](https://github.com/extrawurst/gitui/issues/1951))
1415
* support loading custom syntax highlighting themes from a file [[@acuteenvy](https://github.com/acuteenvy)] ([#2565](https://github.com/gitui-org/gitui/pull/2565))
1516
* Select syntax highlighting theme out of the defaults from syntect [[@vasilismanol](https://github.com/vasilismanol)] ([#1931](https://github.com/extrawurst/gitui/issues/1931))

src/components/commit_details/details.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,18 @@ impl Component for DetailsComponent {
369369
self.key_config.keys.move_down,
370370
) {
371371
self.move_scroll_top(ScrollType::Down).into()
372+
} else if key_match(
373+
e,
374+
self.key_config.keys.page_up,
375+
) {
376+
self.move_scroll_top(ScrollType::PageUp)
377+
.into()
378+
} else if key_match(
379+
e,
380+
self.key_config.keys.page_down,
381+
) {
382+
self.move_scroll_top(ScrollType::PageDown)
383+
.into()
372384
} else if key_match(e, self.key_config.keys.home)
373385
|| key_match(e, self.key_config.keys.shift_up)
374386
{

src/components/utils/scroll_vertical.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ 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

@@ -33,9 +35,14 @@ impl VerticalScroll {
3335
let new_scroll_top = match move_type {
3436
ScrollType::Down => old.saturating_add(1),
3537
ScrollType::Up => old.saturating_sub(1),
38+
ScrollType::PageDown => old
39+
.saturating_sub(1)
40+
.saturating_add(self.visual_height.get()),
41+
ScrollType::PageUp => old
42+
.saturating_add(1)
43+
.saturating_sub(self.visual_height.get()),
3644
ScrollType::Home => 0,
3745
ScrollType::End => max,
38-
_ => old,
3946
};
4047

4148
let new_scroll_top = new_scroll_top.clamp(0, max);
@@ -81,6 +88,8 @@ impl VerticalScroll {
8188
selection_max: usize,
8289
visual_height: usize,
8390
) -> usize {
91+
self.visual_height.set(visual_height);
92+
8493
let new_top = calc_scroll_top(
8594
self.get_top(),
8695
visual_height,
@@ -192,4 +201,26 @@ mod tests {
192201
scroll.move_area_to_visible(visual_height, 0, 2);
193202
assert_eq!(scroll.get_top(), 0);
194203
}
204+
205+
#[test]
206+
fn test_scroll_with_pageup_pagedown() {
207+
let scroll = VerticalScroll::new();
208+
scroll.max_top.set(10);
209+
scroll.visual_height.set(8);
210+
211+
assert!(scroll.move_top(ScrollType::End));
212+
assert_eq!(scroll.get_top(), 10);
213+
214+
assert!(!scroll.move_top(ScrollType::PageDown));
215+
assert_eq!(scroll.get_top(), 10);
216+
217+
assert!(scroll.move_top(ScrollType::PageUp));
218+
assert_eq!(scroll.get_top(), 3);
219+
220+
assert!(scroll.move_top(ScrollType::PageUp));
221+
assert_eq!(scroll.get_top(), 0);
222+
223+
assert!(!scroll.move_top(ScrollType::PageUp));
224+
assert_eq!(scroll.get_top(), 0);
225+
}
195226
}

0 commit comments

Comments
 (0)