cleanup and improvements

inspired by #1411
This commit is contained in:
extrawurst 2023-08-26 14:37:15 +02:00
parent 6339a1f33c
commit 5b2b8c7e0a
2 changed files with 19 additions and 21 deletions

View file

@ -2,10 +2,10 @@ use crate::{
accessors,
cmdbar::CommandBar,
components::{
event_pump, AppOption, BlameFileComponent,
BranchListComponent, CommandBlocking, CommandInfo,
CommitComponent, CompareCommitsComponent, Component,
ConfirmComponent, CreateBranchComponent, DrawableComponent,
command_pump, event_pump, AppOption, BlameFileComponent,
BranchListComponent, CommandInfo, CommitComponent,
CompareCommitsComponent, Component, ConfirmComponent,
CreateBranchComponent, DrawableComponent,
ExternalEditorComponent, FetchComponent, FileRevlogComponent,
FuzzyFindPopup, FuzzyFinderTarget, HelpComponent,
InspectCommitComponent, LogSearchPopupComponent,
@ -1116,14 +1116,7 @@ impl App {
fn commands(&self, force_all: bool) -> Vec<CommandInfo> {
let mut res = Vec::new();
for c in self.components() {
if c.commands(&mut res, force_all)
!= CommandBlocking::PassingOn
&& !force_all
{
break;
}
}
command_pump(&mut res, force_all, &self.components());
res.push(CommandInfo::new(
strings::commands::find_file(&self.key_config),

View file

@ -115,6 +115,9 @@ impl Component for BranchListComponent {
out.clear();
}
let selection_is_cur_branch =
self.selection_is_cur_branch();
out.push(CommandInfo::new(
strings::commands::scroll(&self.key_config),
true,
@ -139,7 +142,7 @@ impl Component for BranchListComponent {
strings::commands::compare_with_head(
&self.key_config,
),
!self.selection_is_cur_branch(),
!selection_is_cur_branch,
true,
));
@ -156,8 +159,7 @@ impl Component for BranchListComponent {
strings::commands::select_branch_popup(
&self.key_config,
),
!self.selection_is_cur_branch()
&& self.valid_selection(),
!selection_is_cur_branch && self.valid_selection(),
true,
));
@ -173,7 +175,7 @@ impl Component for BranchListComponent {
strings::commands::delete_branch_popup(
&self.key_config,
),
!self.selection_is_cur_branch(),
!selection_is_cur_branch,
true,
));
@ -181,7 +183,7 @@ impl Component for BranchListComponent {
strings::commands::merge_branch_popup(
&self.key_config,
),
!self.selection_is_cur_branch(),
!selection_is_cur_branch,
true,
));
@ -189,7 +191,7 @@ impl Component for BranchListComponent {
strings::commands::branch_popup_rebase(
&self.key_config,
),
!self.selection_is_cur_branch(),
!selection_is_cur_branch,
true,
));
@ -228,6 +230,9 @@ impl Component for BranchListComponent {
return Ok(EventState::Consumed);
}
let selection_is_cur_branch =
self.selection_is_cur_branch();
if key_match(e, self.key_config.keys.enter) {
try_or_popup!(
self,
@ -243,12 +248,12 @@ impl Component for BranchListComponent {
{
self.rename_branch();
} else if key_match(e, self.key_config.keys.delete_branch)
&& !self.selection_is_cur_branch()
&& !selection_is_cur_branch
&& self.valid_selection()
{
self.delete_branch();
} else if key_match(e, self.key_config.keys.merge_branch)
&& !self.selection_is_cur_branch()
&& !selection_is_cur_branch
&& self.valid_selection()
{
try_or_popup!(
@ -257,7 +262,7 @@ impl Component for BranchListComponent {
self.merge_branch()
);
} else if key_match(e, self.key_config.keys.rebase_branch)
&& !self.selection_is_cur_branch()
&& !selection_is_cur_branch
&& self.valid_selection()
{
try_or_popup!(