Skip to content

Commit 5b2b8c7

Browse files
committed
cleanup and improvements
inspired by #1411
1 parent 6339a1f commit 5b2b8c7

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/app.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use crate::{
22
accessors,
33
cmdbar::CommandBar,
44
components::{
5-
event_pump, AppOption, BlameFileComponent,
6-
BranchListComponent, CommandBlocking, CommandInfo,
7-
CommitComponent, CompareCommitsComponent, Component,
8-
ConfirmComponent, CreateBranchComponent, DrawableComponent,
5+
command_pump, event_pump, AppOption, BlameFileComponent,
6+
BranchListComponent, CommandInfo, CommitComponent,
7+
CompareCommitsComponent, Component, ConfirmComponent,
8+
CreateBranchComponent, DrawableComponent,
99
ExternalEditorComponent, FetchComponent, FileRevlogComponent,
1010
FuzzyFindPopup, FuzzyFinderTarget, HelpComponent,
1111
InspectCommitComponent, LogSearchPopupComponent,
@@ -1116,14 +1116,7 @@ impl App {
11161116
fn commands(&self, force_all: bool) -> Vec<CommandInfo> {
11171117
let mut res = Vec::new();
11181118

1119-
for c in self.components() {
1120-
if c.commands(&mut res, force_all)
1121-
!= CommandBlocking::PassingOn
1122-
&& !force_all
1123-
{
1124-
break;
1125-
}
1126-
}
1119+
command_pump(&mut res, force_all, &self.components());
11271120

11281121
res.push(CommandInfo::new(
11291122
strings::commands::find_file(&self.key_config),

src/components/branchlist.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ impl Component for BranchListComponent {
115115
out.clear();
116116
}
117117

118+
let selection_is_cur_branch =
119+
self.selection_is_cur_branch();
120+
118121
out.push(CommandInfo::new(
119122
strings::commands::scroll(&self.key_config),
120123
true,
@@ -139,7 +142,7 @@ impl Component for BranchListComponent {
139142
strings::commands::compare_with_head(
140143
&self.key_config,
141144
),
142-
!self.selection_is_cur_branch(),
145+
!selection_is_cur_branch,
143146
true,
144147
));
145148

@@ -156,8 +159,7 @@ impl Component for BranchListComponent {
156159
strings::commands::select_branch_popup(
157160
&self.key_config,
158161
),
159-
!self.selection_is_cur_branch()
160-
&& self.valid_selection(),
162+
!selection_is_cur_branch && self.valid_selection(),
161163
true,
162164
));
163165

@@ -173,23 +175,23 @@ impl Component for BranchListComponent {
173175
strings::commands::delete_branch_popup(
174176
&self.key_config,
175177
),
176-
!self.selection_is_cur_branch(),
178+
!selection_is_cur_branch,
177179
true,
178180
));
179181

180182
out.push(CommandInfo::new(
181183
strings::commands::merge_branch_popup(
182184
&self.key_config,
183185
),
184-
!self.selection_is_cur_branch(),
186+
!selection_is_cur_branch,
185187
true,
186188
));
187189

188190
out.push(CommandInfo::new(
189191
strings::commands::branch_popup_rebase(
190192
&self.key_config,
191193
),
192-
!self.selection_is_cur_branch(),
194+
!selection_is_cur_branch,
193195
true,
194196
));
195197

@@ -228,6 +230,9 @@ impl Component for BranchListComponent {
228230
return Ok(EventState::Consumed);
229231
}
230232

233+
let selection_is_cur_branch =
234+
self.selection_is_cur_branch();
235+
231236
if key_match(e, self.key_config.keys.enter) {
232237
try_or_popup!(
233238
self,
@@ -243,12 +248,12 @@ impl Component for BranchListComponent {
243248
{
244249
self.rename_branch();
245250
} else if key_match(e, self.key_config.keys.delete_branch)
246-
&& !self.selection_is_cur_branch()
251+
&& !selection_is_cur_branch
247252
&& self.valid_selection()
248253
{
249254
self.delete_branch();
250255
} else if key_match(e, self.key_config.keys.merge_branch)
251-
&& !self.selection_is_cur_branch()
256+
&& !selection_is_cur_branch
252257
&& self.valid_selection()
253258
{
254259
try_or_popup!(
@@ -257,7 +262,7 @@ impl Component for BranchListComponent {
257262
self.merge_branch()
258263
);
259264
} else if key_match(e, self.key_config.keys.rebase_branch)
260-
&& !self.selection_is_cur_branch()
265+
&& !selection_is_cur_branch
261266
&& self.valid_selection()
262267
{
263268
try_or_popup!(

0 commit comments

Comments
 (0)