diff --git a/assets/vim_style_key_config.ron b/assets/vim_style_key_config.ron index 1ebe723f..5dabc47a 100644 --- a/assets/vim_style_key_config.ron +++ b/assets/vim_style_key_config.ron @@ -16,6 +16,7 @@ tab_toggle: ( code: Tab, modifiers: ( bits: 0,),), tab_toggle_reverse: ( code: BackTab, modifiers: ( bits: 1,),), + toggle_workarea: ( code: Char('w'), modifiers: (bits: 0,),), focus_right: ( code: Char('l'), modifiers: ( bits: 0,),), focus_left: ( code: Char('h'), modifiers: ( bits: 0,),), diff --git a/src/keys.rs b/src/keys.rs index 18f8afea..63073f8b 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -26,6 +26,7 @@ pub struct KeyConfig { pub tab_stashes: KeyEvent, pub tab_toggle: KeyEvent, pub tab_toggle_reverse: KeyEvent, + pub toggle_workarea: KeyEvent, pub focus_right: KeyEvent, pub focus_left: KeyEvent, pub focus_above: KeyEvent, @@ -80,6 +81,7 @@ impl Default for KeyConfig { tab_stashes: KeyEvent { code: KeyCode::Char('4'), modifiers: KeyModifiers::empty()}, tab_toggle: KeyEvent { code: KeyCode::Tab, modifiers: KeyModifiers::empty()}, tab_toggle_reverse: KeyEvent { code: KeyCode::BackTab, modifiers: KeyModifiers::SHIFT}, + toggle_workarea: KeyEvent { code: KeyCode::Char('w'), modifiers: KeyModifiers::empty()}, focus_right: KeyEvent { code: KeyCode::Right, modifiers: KeyModifiers::empty()}, focus_left: KeyEvent { code: KeyCode::Left, modifiers: KeyModifiers::empty()}, focus_above: KeyEvent { code: KeyCode::Up, modifiers: KeyModifiers::empty()}, diff --git a/src/strings.rs b/src/strings.rs index 33c44e3d..c84942d5 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -503,6 +503,30 @@ pub mod commands { CMD_GROUP_GENERAL, ) } + pub fn select_staging( + key_config: &SharedKeyConfig, + ) -> CommandText { + CommandText::new( + format!( + "To stage [{}]", + key_config.get_hint(key_config.toggle_workarea), + ), + "focus/select staging area", + CMD_GROUP_GENERAL, + ) + } + pub fn select_unstaged( + key_config: &SharedKeyConfig, + ) -> CommandText { + CommandText::new( + format!( + "To unstaged [{}]", + key_config.get_hint(key_config.toggle_workarea), + ), + "focus/select unstaged area", + CMD_GROUP_GENERAL, + ) + } pub fn commit_open(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 759d995b..bc3477a3 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -35,6 +35,17 @@ enum Focus { Stage, } +/// focus can toggle between workdir and stage +impl Focus { + const fn toggled_focus(&self) -> Self { + match self { + Self::WorkDir => Self::Stage, + Self::Stage => Self::WorkDir, + Self::Diff => Self::Diff, + } + } +} + /// which target are we showing a diff against #[derive(PartialEq, Copy, Clone)] enum DiffTarget { @@ -515,6 +526,32 @@ impl Component for Status { self.can_focus_diff(), (self.visible && !focus_on_diff) || force_all, )); + out.push( + CommandInfo::new( + strings::commands::select_staging( + &self.key_config, + ), + !focus_on_diff, + (self.visible + && !focus_on_diff + && self.focus == Focus::WorkDir) + || force_all, + ) + .order(strings::order::NAV), + ); + out.push( + CommandInfo::new( + strings::commands::select_unstaged( + &self.key_config, + ), + !focus_on_diff, + (self.visible + && !focus_on_diff + && self.focus == Focus::Stage) + || force_all, + ) + .order(strings::order::NAV), + ); out.push( CommandInfo::new( @@ -551,6 +588,10 @@ impl Component for Status { ); } Ok(true) + } else if k == self.key_config.toggle_workarea + && !self.is_focus_on_diff() + { + self.switch_focus(self.focus.toggled_focus()) } else if k == self.key_config.focus_right && self.can_focus_diff() {