From 6ae5b5e2b24a2dc63388876d0ef2fa306c59601a Mon Sep 17 00:00:00 2001 From: Alessandro Menezes Date: Sat, 9 Oct 2021 20:58:21 -0400 Subject: [PATCH] Add specific key bindings to stage / unstage items (#930) * Add specific key bindings to stage / unstage items Feature requested by Issue #909. * Updating Help popup with stage / unstage keys * Merging staging and unstaging into a single `stage_unstage_item` key * Add/remove hunk now use the `stage_unstage_item` key --- CHANGELOG.md | 1 + src/components/changes.rs | 2 +- src/components/diff.rs | 2 +- src/keys.rs | 2 ++ src/strings.rs | 8 ++++---- vim_style_key_config.ron | 2 ++ 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2e72978..b320f930 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Added - support rebasing branches with conflicts ([#895](https://github.com/extrawurst/gitui/issues/895)) +- add a key binding to stage / unstage items [[@alessandroasm](https://github.com/alessandroasm)] ([#909](https://github.com/extrawurst/gitui/issues/909)) - switch to status tab after merging or rebasing with conflicts ([#926](https://github.com/extrawurst/gitui/issues/926)) ## Fixed diff --git a/src/components/changes.rs b/src/components/changes.rs index 86fa8013..45f9a036 100644 --- a/src/components/changes.rs +++ b/src/components/changes.rs @@ -233,7 +233,7 @@ impl Component for ChangesComponent { if self.focused() { if let Event::Key(e) = ev { - return if e == self.key_config.enter { + return if e == self.key_config.stage_unstage_item { try_or_popup!( self, "staging error:", diff --git a/src/components/diff.rs b/src/components/diff.rs index 598c96ce..08bba563 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -738,7 +738,7 @@ impl Component for DiffComponent { } else if e == self.key_config.page_down { self.move_selection(ScrollType::PageDown); Ok(EventState::Consumed) - } else if e == self.key_config.enter + } else if e == self.key_config.stage_unstage_item && !self.is_immutable { try_or_popup!( diff --git a/src/keys.rs b/src/keys.rs index 0b6a78a3..8af76291 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -88,6 +88,7 @@ pub struct KeyConfig { pub pull: KeyEvent, pub abort_merge: KeyEvent, pub undo_commit: KeyEvent, + pub stage_unstage_item: KeyEvent, } #[rustfmt::skip] @@ -161,6 +162,7 @@ impl Default for KeyConfig { abort_merge: KeyEvent { code: KeyCode::Char('A'), modifiers: KeyModifiers::SHIFT}, open_file_tree: KeyEvent { code: KeyCode::Char('F'), modifiers: KeyModifiers::SHIFT}, file_find: KeyEvent { code: KeyCode::Char('f'), modifiers: KeyModifiers::empty()}, + stage_unstage_item: KeyEvent { code: KeyCode::Enter, modifiers: KeyModifiers::empty()}, } } } diff --git a/src/strings.rs b/src/strings.rs index 0ed98e03..b6a7e614 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -526,7 +526,7 @@ pub mod commands { CommandText::new( format!( "Add hunk [{}]", - key_config.get_hint(key_config.enter), + key_config.get_hint(key_config.stage_unstage_item), ), "adds selected hunk to stage", CMD_GROUP_DIFF, @@ -586,7 +586,7 @@ pub mod commands { CommandText::new( format!( "Remove hunk [{}]", - key_config.get_hint(key_config.enter), + key_config.get_hint(key_config.stage_unstage_item), ), "removes selected hunk from stage", CMD_GROUP_DIFF, @@ -751,7 +751,7 @@ pub mod commands { CommandText::new( format!( "Stage [{}]", - key_config.get_hint(key_config.enter), + key_config.get_hint(key_config.stage_unstage_item), ), "stage currently selected file or entire path", CMD_GROUP_CHANGES, @@ -771,7 +771,7 @@ pub mod commands { CommandText::new( format!( "Unstage [{}]", - key_config.get_hint(key_config.enter), + key_config.get_hint(key_config.stage_unstage_item), ), "unstage currently selected file or entire path", CMD_GROUP_CHANGES, diff --git a/vim_style_key_config.ron b/vim_style_key_config.ron index 1477ef5a..7938cd85 100644 --- a/vim_style_key_config.ron +++ b/vim_style_key_config.ron @@ -100,6 +100,8 @@ open_file_tree: ( code: Char('F'), modifiers: ( bits: 1,),), file_find: ( code: Char('f'), modifiers: ( bits: 0,),), + stage_unstage_item: ( code: Enter, modifiers: ( bits: 0,),), + //removed in 0.11 //tab_toggle_reverse_windows: ( code: BackTab, modifiers: ( bits: 1,),), )