Add g to toggle between staging and workdir (workarea) (#595)

closes #594
This commit is contained in:
Benedikt Terhechte 2021-03-21 18:37:53 +01:00 committed by GitHub
parent 63e5b29b57
commit 656561e3eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 0 deletions

View file

@ -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,),),

View file

@ -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()},

View file

@ -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!(

View file

@ -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()
{