Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* increase MSRV from 1.81 to 1.82 [[@cruessler](https://github.com/cruessler)]

### Added
* Message tab supports pageUp and pageDown [[@xlai89](https://github.com/xlai89)] ([#2623](https://github.com/extrawurst/gitui/issues/2623))
* Files and status tab support pageUp and pageDown [[@fatpandac](https://github.com/fatpandac)] ([#1951](https://github.com/extrawurst/gitui/issues/1951))
* support loading custom syntax highlighting themes from a file [[@acuteenvy](https://github.com/acuteenvy)] ([#2565](https://github.com/gitui-org/gitui/pull/2565))
* Select syntax highlighting theme out of the defaults from syntect [[@vasilismanol](https://github.com/vasilismanol)] ([#1931](https://github.com/extrawurst/gitui/issues/1931))
Expand Down
12 changes: 12 additions & 0 deletions src/components/commit_details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ impl Component for DetailsComponent {
self.key_config.keys.move_down,
) {
self.move_scroll_top(ScrollType::Down).into()
} else if key_match(
e,
self.key_config.keys.page_up,
) {
self.move_scroll_top(ScrollType::PageUp)
.into()
} else if key_match(
e,
self.key_config.keys.page_down,
) {
self.move_scroll_top(ScrollType::PageDown)
.into()
} else if key_match(e, self.key_config.keys.home)
|| key_match(e, self.key_config.keys.shift_up)
{
Expand Down
33 changes: 32 additions & 1 deletion src/components/utils/scroll_vertical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use std::cell::Cell;
pub struct VerticalScroll {
top: Cell<usize>,
max_top: Cell<usize>,
visual_height: Cell<usize>,
}

impl VerticalScroll {
pub const fn new() -> Self {
Self {
top: Cell::new(0),
max_top: Cell::new(0),
visual_height: Cell::new(0),
}
}

Expand All @@ -33,9 +35,14 @@ impl VerticalScroll {
let new_scroll_top = match move_type {
ScrollType::Down => old.saturating_add(1),
ScrollType::Up => old.saturating_sub(1),
ScrollType::PageDown => old
.saturating_sub(1)
.saturating_add(self.visual_height.get()),
ScrollType::PageUp => old
.saturating_add(1)
.saturating_sub(self.visual_height.get()),
ScrollType::Home => 0,
ScrollType::End => max,
_ => old,
};

let new_scroll_top = new_scroll_top.clamp(0, max);
Expand Down Expand Up @@ -81,6 +88,8 @@ impl VerticalScroll {
selection_max: usize,
visual_height: usize,
) -> usize {
self.visual_height.set(visual_height);

let new_top = calc_scroll_top(
self.get_top(),
visual_height,
Expand Down Expand Up @@ -192,4 +201,26 @@ mod tests {
scroll.move_area_to_visible(visual_height, 0, 2);
assert_eq!(scroll.get_top(), 0);
}

#[test]
fn test_scroll_with_pageup_pagedown() {
let scroll = VerticalScroll::new();
scroll.max_top.set(10);
scroll.visual_height.set(8);

assert!(scroll.move_top(ScrollType::End));
assert_eq!(scroll.get_top(), 10);

assert!(!scroll.move_top(ScrollType::PageDown));
assert_eq!(scroll.get_top(), 10);

assert!(scroll.move_top(ScrollType::PageUp));
assert_eq!(scroll.get_top(), 3);

assert!(scroll.move_top(ScrollType::PageUp));
assert_eq!(scroll.get_top(), 0);

assert!(!scroll.move_top(ScrollType::PageUp));
assert_eq!(scroll.get_top(), 0);
}
}
Loading