Skip to content

Commit af5914b

Browse files
terhechteStephan Dilly
authored and
Stephan Dilly
committed
Add g to toggle between staging and workdir (workarea) (#595)
closes #594
1 parent 96548f7 commit af5914b

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

assets/vim_style_key_config.ron

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
tab_toggle: ( code: Tab, modifiers: ( bits: 0,),),
1818
tab_toggle_reverse: ( code: BackTab, modifiers: ( bits: 1,),),
19+
toggle_workarea: ( code: Char('w'), modifiers: (bits: 0,),),
1920

2021
focus_right: ( code: Char('l'), modifiers: ( bits: 0,),),
2122
focus_left: ( code: Char('h'), modifiers: ( bits: 0,),),

src/keys.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct KeyConfig {
2626
pub tab_stashes: KeyEvent,
2727
pub tab_toggle: KeyEvent,
2828
pub tab_toggle_reverse: KeyEvent,
29+
pub toggle_workarea: KeyEvent,
2930
pub focus_right: KeyEvent,
3031
pub focus_left: KeyEvent,
3132
pub focus_above: KeyEvent,
@@ -80,6 +81,7 @@ impl Default for KeyConfig {
8081
tab_stashes: KeyEvent { code: KeyCode::Char('4'), modifiers: KeyModifiers::empty()},
8182
tab_toggle: KeyEvent { code: KeyCode::Tab, modifiers: KeyModifiers::empty()},
8283
tab_toggle_reverse: KeyEvent { code: KeyCode::BackTab, modifiers: KeyModifiers::SHIFT},
84+
toggle_workarea: KeyEvent { code: KeyCode::Char('w'), modifiers: KeyModifiers::empty()},
8385
focus_right: KeyEvent { code: KeyCode::Right, modifiers: KeyModifiers::empty()},
8486
focus_left: KeyEvent { code: KeyCode::Left, modifiers: KeyModifiers::empty()},
8587
focus_above: KeyEvent { code: KeyCode::Up, modifiers: KeyModifiers::empty()},

src/strings.rs

+24
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,30 @@ pub mod commands {
503503
CMD_GROUP_GENERAL,
504504
)
505505
}
506+
pub fn select_staging(
507+
key_config: &SharedKeyConfig,
508+
) -> CommandText {
509+
CommandText::new(
510+
format!(
511+
"To stage [{}]",
512+
key_config.get_hint(key_config.toggle_workarea),
513+
),
514+
"focus/select staging area",
515+
CMD_GROUP_GENERAL,
516+
)
517+
}
518+
pub fn select_unstaged(
519+
key_config: &SharedKeyConfig,
520+
) -> CommandText {
521+
CommandText::new(
522+
format!(
523+
"To unstaged [{}]",
524+
key_config.get_hint(key_config.toggle_workarea),
525+
),
526+
"focus/select unstaged area",
527+
CMD_GROUP_GENERAL,
528+
)
529+
}
506530
pub fn commit_open(key_config: &SharedKeyConfig) -> CommandText {
507531
CommandText::new(
508532
format!(

src/tabs/status.rs

+41
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ enum Focus {
3535
Stage,
3636
}
3737

38+
/// focus can toggle between workdir and stage
39+
impl Focus {
40+
const fn toggled_focus(&self) -> Self {
41+
match self {
42+
Self::WorkDir => Self::Stage,
43+
Self::Stage => Self::WorkDir,
44+
Self::Diff => Self::Diff,
45+
}
46+
}
47+
}
48+
3849
/// which target are we showing a diff against
3950
#[derive(PartialEq, Copy, Clone)]
4051
enum DiffTarget {
@@ -515,6 +526,32 @@ impl Component for Status {
515526
self.can_focus_diff(),
516527
(self.visible && !focus_on_diff) || force_all,
517528
));
529+
out.push(
530+
CommandInfo::new(
531+
strings::commands::select_staging(
532+
&self.key_config,
533+
),
534+
!focus_on_diff,
535+
(self.visible
536+
&& !focus_on_diff
537+
&& self.focus == Focus::WorkDir)
538+
|| force_all,
539+
)
540+
.order(strings::order::NAV),
541+
);
542+
out.push(
543+
CommandInfo::new(
544+
strings::commands::select_unstaged(
545+
&self.key_config,
546+
),
547+
!focus_on_diff,
548+
(self.visible
549+
&& !focus_on_diff
550+
&& self.focus == Focus::Stage)
551+
|| force_all,
552+
)
553+
.order(strings::order::NAV),
554+
);
518555

519556
out.push(
520557
CommandInfo::new(
@@ -551,6 +588,10 @@ impl Component for Status {
551588
);
552589
}
553590
Ok(true)
591+
} else if k == self.key_config.toggle_workarea
592+
&& !self.is_focus_on_diff()
593+
{
594+
self.switch_focus(self.focus.toggled_focus())
554595
} else if k == self.key_config.focus_right
555596
&& self.can_focus_diff()
556597
{

0 commit comments

Comments
 (0)