Skip to content

Commit

Permalink
Only count existing branches in picker search (#22908)
Browse files Browse the repository at this point in the history
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.

<img width="530" alt="Screenshot 2025-01-09 at 12 17 30"
src="https://github.com/user-attachments/assets/c4e6ac6f-d842-4b2f-a3af-ec28c9d90f0a"
/>

Closes #22905.

Release Notes:

- Fixed result count in branch picker searches.

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
  • Loading branch information
AaronFeickert and maxdeviant authored Jan 9, 2025
1 parent 9ea7ed8 commit 8b4370f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/vcs_menu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
});
Expand Down

0 comments on commit 8b4370f

Please sign in to comment.