From 8b4370f1704bee5f3d606dde984bb66f5d1bfc0e Mon Sep 17 00:00:00 2001
From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com>
Date: Thu, 9 Jan 2025 12:55:19 -0600
Subject: [PATCH] Only count existing branches in picker search (#22908)
When displaying the number of matches in the branch picker during a
search, don't count the "create new branch" option as a match, since it
only appears when _no_ existing branches are found.
Closes #22905.
Release Notes:
- Fixed result count in branch picker searches.
---------
Co-authored-by: Marshall Bowers
---
crates/vcs_menu/src/lib.rs | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/crates/vcs_menu/src/lib.rs b/crates/vcs_menu/src/lib.rs
index 5dc02cc7c22538da155e15434042f69e30b18054..d66628c2d15a13cd3034cf494d918ff106356a9d 100644
--- a/crates/vcs_menu/src/lib.rs
+++ b/crates/vcs_menu/src/lib.rs
@@ -128,6 +128,13 @@ impl BranchListDelegate {
branch_name_trailoff_after,
})
}
+
+ fn branch_count(&self) -> usize {
+ self.matches
+ .iter()
+ .filter(|item| matches!(item, BranchEntry::Branch(_)))
+ .count()
+ }
}
impl PickerDelegate for BranchListDelegate {
@@ -308,8 +315,8 @@ impl PickerDelegate for BranchListDelegate {
.into_any_element()
} else {
let match_label = self.matches.is_empty().not().then(|| {
- let suffix = if self.matches.len() == 1 { "" } else { "es" };
- Label::new(format!("{} match{}", self.matches.len(), suffix))
+ let suffix = if self.branch_count() == 1 { "" } else { "es" };
+ Label::new(format!("{} match{}", self.branch_count(), suffix))
.color(Color::Muted)
.size(LabelSize::Small)
});