diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b68fe73..27b0bb73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/app.rs b/src/app.rs index a56d6d91..6c90a590 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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) } diff --git a/src/keys.rs b/src/keys.rs index 50df78cd..340d3b9a 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -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);