fix missing paging support in branch list (#539)

closes #519
This commit is contained in:
Stephan Dilly 2021-02-23 19:07:01 +01:00 committed by GitHub
parent e3bb51b277
commit 1b8b58a31c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -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))

View file

@ -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<usize>,
current_height: Cell<u16>,
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,
};