Skip to content

Commit 9dc5e53

Browse files
author
Stephan Dilly
committed
cleanup commands in status/diff (closes #572)
1 parent 00eca12 commit 9dc5e53

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515
- `[s]` key repurposed to trigger line based (un)stage
16+
- cleanup status/diff commands to be more context sensitive ([#572](https://github.com/extrawurst/gitui/issues/572))
1617

1718
### Added
1819
- support pull via rebase (using config `pull.rebase`) ([#566](https://github.com/extrawurst/gitui/issues/566))

src/components/diff.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,6 @@ impl Component for DiffComponent {
675675
self.focused,
676676
));
677677

678-
out.push(CommandInfo::new(
679-
strings::commands::copy(&self.key_config),
680-
true,
681-
self.focused,
682-
));
683-
684678
out.push(
685679
CommandInfo::new(
686680
strings::commands::diff_home_end(&self.key_config),
@@ -730,6 +724,12 @@ impl Component for DiffComponent {
730724
));
731725
}
732726

727+
out.push(CommandInfo::new(
728+
strings::commands::copy(&self.key_config),
729+
true,
730+
self.focused,
731+
));
732+
733733
CommandBlocking::PassingOn
734734
}
735735

src/tabs/status.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ impl Status {
232232
}
233233
}
234234

235+
fn is_focus_on_diff(&self) -> bool {
236+
self.focus == Focus::Diff
237+
}
238+
235239
fn switch_focus(&mut self, f: Focus) -> Result<bool> {
236240
if self.focus != f {
237241
self.focus = f;
@@ -455,6 +459,8 @@ impl Component for Status {
455459
out: &mut Vec<CommandInfo>,
456460
force_all: bool,
457461
) -> CommandBlocking {
462+
let focus_on_diff = self.is_focus_on_diff();
463+
458464
if self.visible || force_all {
459465
command_pump(
460466
out,
@@ -467,30 +473,29 @@ impl Component for Status {
467473
&self.key_config,
468474
),
469475
true,
470-
true,
476+
!focus_on_diff,
471477
));
472478

473479
out.push(CommandInfo::new(
474480
strings::commands::status_push(&self.key_config),
475481
self.can_push(),
476-
true,
482+
!focus_on_diff,
477483
));
478484
out.push(CommandInfo::new(
479485
strings::commands::status_force_push(
480486
&self.key_config,
481487
),
482-
self.can_push(),
483488
true,
489+
self.can_push() && !focus_on_diff,
484490
));
485491
out.push(CommandInfo::new(
486492
strings::commands::status_pull(&self.key_config),
487493
true,
488-
true,
494+
!focus_on_diff,
489495
));
490496
}
491497

492498
{
493-
let focus_on_diff = self.focus == Focus::Diff;
494499
out.push(CommandInfo::new(
495500
strings::commands::edit_item(&self.key_config),
496501
if focus_on_diff {
@@ -510,17 +515,18 @@ impl Component for Status {
510515
self.can_focus_diff(),
511516
(self.visible && !focus_on_diff) || force_all,
512517
));
513-
}
514518

515-
out.push(
516-
CommandInfo::new(
517-
strings::commands::select_status(&self.key_config),
518-
true,
519-
(self.visible && self.focus == Focus::Diff)
520-
|| force_all,
521-
)
522-
.hidden(),
523-
);
519+
out.push(
520+
CommandInfo::new(
521+
strings::commands::select_status(
522+
&self.key_config,
523+
),
524+
true,
525+
(self.visible && !focus_on_diff) || force_all,
526+
)
527+
.hidden(),
528+
);
529+
}
524530

525531
visibility_blocking(self)
526532
}
@@ -535,7 +541,7 @@ impl Component for Status {
535541
if let Event::Key(k) = ev {
536542
return if k == self.key_config.edit_file
537543
&& (self.can_focus_diff()
538-
|| self.focus == Focus::Diff)
544+
|| self.is_focus_on_diff())
539545
{
540546
if let Some((path, _)) = self.selected_path() {
541547
self.queue.borrow_mut().push_back(
@@ -564,18 +570,27 @@ impl Component for Status {
564570
&& !self.index_wd.is_empty()
565571
{
566572
self.switch_focus(Focus::WorkDir)
567-
} else if k == self.key_config.select_branch {
573+
} else if k == self.key_config.select_branch
574+
&& !self.is_focus_on_diff()
575+
{
568576
self.queue
569577
.borrow_mut()
570578
.push_back(InternalEvent::SelectBranch);
571579
Ok(true)
572-
} else if k == self.key_config.force_push {
580+
} else if k == self.key_config.force_push
581+
&& !self.is_focus_on_diff()
582+
&& self.can_push()
583+
{
573584
self.push(true);
574585
Ok(true)
575-
} else if k == self.key_config.push {
586+
} else if k == self.key_config.push
587+
&& !self.is_focus_on_diff()
588+
{
576589
self.push(false);
577590
Ok(true)
578-
} else if k == self.key_config.pull {
591+
} else if k == self.key_config.pull
592+
&& !self.is_focus_on_diff()
593+
{
579594
self.pull();
580595
Ok(true)
581596
} else {

0 commit comments

Comments
 (0)