Skip to content

Commit a5d0b47

Browse files
committed
feat: message tab supports pageup and pagedown (#2623)
1 parent 1d22485 commit a5d0b47

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
* execute git-hooks directly if possible (on *nix) else use sh instead of bash (without reading SHELL variable) [[@Joshix](https://github.com/Joshix-1)] ([#2483](https://github.com/extrawurst/gitui/pull/2483))
1010

1111
### Added
12+
* Message tab supports pageUp and pageDown [[@xlai89](https://github.com/xlai89)] ([#2623](https://github.com/extrawurst/gitui/issues/2623))
1213
* Files and status tab support pageUp and pageDown [[@fatpandac](https://github.com/fatpandac)] ([#1951](https://github.com/extrawurst/gitui/issues/1951))
1314
* support loading custom syntax highlighting themes from a file [[@acuteenvy](https://github.com/acuteenvy)] ([#2565](https://github.com/gitui-org/gitui/pull/2565))
1415
* 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: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct DetailsComponent {
3333
tags: Vec<Tag>,
3434
theme: SharedTheme,
3535
focused: bool,
36-
current_width: Cell<u16>,
36+
current_size: Cell<(u16, u16)>,
3737
scroll: VerticalScroll,
3838
scroll_to_bottom_next_draw: Cell<bool>,
3939
key_config: SharedKeyConfig,
@@ -52,7 +52,7 @@ impl DetailsComponent {
5252
theme: env.theme.clone(),
5353
focused,
5454
scroll_to_bottom_next_draw: Cell::new(false),
55-
current_width: Cell::new(0),
55+
current_size: Cell::new((0, 0)),
5656
scroll: VerticalScroll::new(),
5757
key_config: env.key_config.clone(),
5858
}
@@ -246,7 +246,40 @@ impl DetailsComponent {
246246

247247
fn move_scroll_top(&self, move_type: ScrollType) -> bool {
248248
if self.data.is_some() {
249-
self.scroll.move_top(move_type)
249+
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+
}
250283
} else {
251284
false
252285
}
@@ -284,7 +317,7 @@ impl DrawableComponent for DetailsComponent {
284317
let width = chunks[1].width.saturating_sub(border_width);
285318
let height = chunks[1].height.saturating_sub(border_width);
286319

287-
self.current_width.set(width);
320+
self.current_size.set((width, height));
288321

289322
let number_of_lines = Self::get_number_of_lines(
290323
self.data.as_ref(),
@@ -340,7 +373,7 @@ impl Component for DetailsComponent {
340373
out: &mut Vec<CommandInfo>,
341374
force_all: bool,
342375
) -> CommandBlocking {
343-
let width = usize::from(self.current_width.get());
376+
let width = usize::from(self.current_size.get().0);
344377
let number_of_lines =
345378
Self::get_number_of_lines(self.data.as_ref(), width);
346379

@@ -369,6 +402,18 @@ impl Component for DetailsComponent {
369402
self.key_config.keys.move_down,
370403
) {
371404
self.move_scroll_top(ScrollType::Down).into()
405+
} else if key_match(
406+
e,
407+
self.key_config.keys.page_up,
408+
) {
409+
self.move_scroll_top(ScrollType::PageUp)
410+
.into()
411+
} else if key_match(
412+
e,
413+
self.key_config.keys.page_down,
414+
) {
415+
self.move_scroll_top(ScrollType::PageDown)
416+
.into()
372417
} else if key_match(e, self.key_config.keys.home)
373418
|| key_match(e, self.key_config.keys.shift_up)
374419
{

0 commit comments

Comments
 (0)