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] ## [Unreleased]
### Added
- support reverse tabbing using shift+tab ([#92](https://github.com/extrawurst/gitui/issues/92))
## [0.4.0] - 2020-05-25 ## [0.4.0] - 2020-05-25
### Added ### Added

View file

@ -128,7 +128,11 @@ impl App {
} else if let Event::Key(k) = ev { } else if let Event::Key(k) = ev {
let new_flags = match k { let new_flags = match k {
keys::TAB_TOGGLE => { keys::TAB_TOGGLE => {
self.toggle_tabs()?; self.toggle_tabs(false)?;
NeedsUpdate::COMMANDS
}
keys::TAB_TOGGLE_REVERSE => {
self.toggle_tabs(true)?;
NeedsUpdate::COMMANDS NeedsUpdate::COMMANDS
} }
@ -235,12 +239,14 @@ impl App {
] ]
} }
fn toggle_tabs(&mut self) -> Result<()> { fn toggle_tabs(&mut self, reverse: bool) -> Result<()> {
let mut new_tab = self.tab + 1; let tabs_len = self.get_tabs().len();
{ let new_tab = if reverse {
let tabs = self.get_tabs(); self.tab.wrapping_sub(1).min(tabs_len.saturating_sub(1))
new_tab %= tabs.len(); } else {
} self.tab.saturating_add(1) % tabs_len
};
self.set_tab(new_tab) 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: 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_WORKDIR: KeyEvent = no_mod(KeyCode::Char('1'));
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2')); pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right); pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);