From 5b2b8c7e0ad828d3c877c7efbcad27581fa16a0c Mon Sep 17 00:00:00 2001 From: extrawurst Date: Sat, 26 Aug 2023 14:37:15 +0200 Subject: [PATCH] cleanup and improvements inspired by #1411 --- src/app.rs | 17 +++++------------ src/components/branchlist.rs | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/app.rs b/src/app.rs index dbfa1a59..c60fec27 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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 { 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), diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 262c1530..be31f3e6 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -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!(