From 1b8b58a31c42a56f4739aa39b8e1c9a3802acaf7 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Tue, 23 Feb 2021 19:07:01 +0100 Subject: [PATCH] fix missing paging support in branch list (#539) closes #519 --- CHANGELOG.md | 1 + src/components/select_branch.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ef16b65..9214754f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ![push](assets/char_count.gif) ### Fixed +- support missing pageUp/down support in branchlist ([#519](https://github.com/extrawurst/gitui/issues/519)) - don't hide branch name while in commit dialog ([#529](https://github.com/extrawurst/gitui/issues/529)) - don't discard commit message without confirmation ([#530](https://github.com/extrawurst/gitui/issues/530)) - compilation broken on freebsd ([#461](https://github.com/extrawurst/gitui/issues/461)) diff --git a/src/components/select_branch.rs b/src/components/select_branch.rs index f65796f8..3c65e4a3 100644 --- a/src/components/select_branch.rs +++ b/src/components/select_branch.rs @@ -16,7 +16,10 @@ use asyncgit::{ CWD, }; use crossterm::event::Event; -use std::{cell::Cell, convert::TryInto}; +use std::{ + cell::Cell, + convert::{TryFrom, TryInto}, +}; use tui::{ backend::Backend, layout::{Alignment, Rect}, @@ -35,6 +38,7 @@ pub struct SelectBranchComponent { visible: bool, selection: u16, scroll_top: Cell, + current_height: Cell, queue: Queue, theme: SharedTheme, key_config: SharedKeyConfig, @@ -92,6 +96,8 @@ impl DrawableComponent for SelectBranchComponent { self.branch_names.len(), self.scroll_top.get(), ); + + self.current_height.set(u16::try_from(height_in_lines)?); } Ok(()) @@ -155,6 +161,10 @@ impl Component for SelectBranchComponent { return self.move_selection(ScrollType::Up); } else if e == self.key_config.move_up { return self.move_selection(ScrollType::Down); + } else if e == self.key_config.page_down { + return self.move_selection(ScrollType::PageDown); + } else if e == self.key_config.page_up { + return self.move_selection(ScrollType::PageUp); } else if e == self.key_config.enter { if let Err(e) = self.switch_to_selected_branch() { log::error!("switch branch error: {}", e); @@ -232,6 +242,7 @@ impl SelectBranchComponent { queue, theme, key_config, + current_height: Cell::new(0), } } /// Get all the names of the branches in the repo @@ -273,6 +284,12 @@ impl SelectBranchComponent { let mut new_selection = match scroll { ScrollType::Up => self.selection.saturating_add(1), ScrollType::Down => self.selection.saturating_sub(1), + ScrollType::PageDown => self + .selection + .saturating_add(self.current_height.get()), + ScrollType::PageUp => self + .selection + .saturating_sub(self.current_height.get()), _ => self.selection, };