mirror of
https://github.com/gitui-org/gitui.git
synced 2026-10-12 02:14:16 +00:00
feat: message tab supports pageup and pagedown (gitui-org#2623) (#2730)
Co-authored-by: extrawurst <[email protected]>
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::cell::Cell;
|
||||
pub struct VerticalScroll {
|
||||
top: Cell<usize>,
|
||||
max_top: Cell<usize>,
|
||||
visual_height: Cell<usize>,
|
||||
}
|
||||
|
||||
impl VerticalScroll {
|
||||
@@ -15,6 +16,7 @@ impl VerticalScroll {
|
||||
Self {
|
||||
top: Cell::new(0),
|
||||
max_top: Cell::new(0),
|
||||
visual_height: Cell::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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,
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user