support reverse tabbing (#92)

This commit is contained in:
Stephan Dilly 2020-05-27 22:09:15 +02:00
parent 55f9dd466c
commit 32bd4e2c60
3 changed files with 17 additions and 7 deletions

View file

@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- support reverse tabbing using shift+tab ([#92](https://github.com/extrawurst/gitui/issues/92))
## [0.4.0] - 2020-05-25
### Added

View file

@ -128,7 +128,11 @@ impl App {
} else if let Event::Key(k) = ev {
let new_flags = match k {
keys::TAB_TOGGLE => {
self.toggle_tabs()?;
self.toggle_tabs(false)?;
NeedsUpdate::COMMANDS
}
keys::TAB_TOGGLE_REVERSE => {
self.toggle_tabs(true)?;
NeedsUpdate::COMMANDS
}
@ -235,12 +239,14 @@ impl App {
]
}
fn toggle_tabs(&mut self) -> Result<()> {
let mut new_tab = self.tab + 1;
{
let tabs = self.get_tabs();
new_tab %= tabs.len();
}
fn toggle_tabs(&mut self, reverse: bool) -> Result<()> {
let tabs_len = self.get_tabs().len();
let new_tab = if reverse {
self.tab.wrapping_sub(1).min(tabs_len.saturating_sub(1))
} else {
self.tab.saturating_add(1) % tabs_len
};
self.set_tab(new_tab)
}

View file

@ -15,6 +15,7 @@ const fn with_mod(
}
pub const TAB_TOGGLE: KeyEvent = no_mod(KeyCode::Tab);
pub const TAB_TOGGLE_REVERSE: KeyEvent = no_mod(KeyCode::BackTab);
pub const FOCUS_WORKDIR: KeyEvent = no_mod(KeyCode::Char('1'));
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);