editor: Add active match highlight for buffer and project search (#44098)

Closes #28617

<img width="400" alt="image"
src="https://github.com/user-attachments/assets/b1c2880c-5744-4bed-a687-5c5e7aa7fef5"
/>

Release Notes:

- Improved visibility of the currently active match when browsing
results in buffer or project search.

---------

Co-authored-by: DarkMatter-999 <darkmatter999official@gmail.com>
This commit is contained in:
Smit Barmase
2025-12-04 03:55:04 +05:30
committed by GitHub
co-authored by DarkMatter-999
parent 87976e91cf
commit 8ad3a150c8
23 changed files with 342 additions and 149 deletions
+16 -3
View File
@@ -96,6 +96,7 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
fn update_matches(
&mut self,
matches: &[Self::Match],
active_match_index: Option<usize>,
window: &mut Window,
cx: &mut Context<Self>,
);
@@ -179,7 +180,13 @@ pub trait SearchableItemHandle: ItemHandle {
handler: Box<dyn Fn(&SearchEvent, &mut Window, &mut App) + Send>,
) -> Subscription;
fn clear_matches(&self, window: &mut Window, cx: &mut App);
fn update_matches(&self, matches: &AnyVec<dyn Send>, window: &mut Window, cx: &mut App);
fn update_matches(
&self,
matches: &AnyVec<dyn Send>,
active_match_index: Option<usize>,
window: &mut Window,
cx: &mut App,
);
fn query_suggestion(&self, window: &mut Window, cx: &mut App) -> String;
fn activate_match(
&self,
@@ -264,10 +271,16 @@ impl<T: SearchableItem> SearchableItemHandle for Entity<T> {
fn clear_matches(&self, window: &mut Window, cx: &mut App) {
self.update(cx, |this, cx| this.clear_matches(window, cx));
}
fn update_matches(&self, matches: &AnyVec<dyn Send>, window: &mut Window, cx: &mut App) {
fn update_matches(
&self,
matches: &AnyVec<dyn Send>,
active_match_index: Option<usize>,
window: &mut Window,
cx: &mut App,
) {
let matches = matches.downcast_ref().unwrap();
self.update(cx, |this, cx| {
this.update_matches(matches.as_slice(), window, cx)
this.update_matches(matches.as_slice(), active_match_index, window, cx)
});
}
fn query_suggestion(&self, window: &mut Window, cx: &mut App) -> String {