Search in selections (#10831)

Release Notes:

- Adding [#8617 ](https://github.com/zed-industries/zed/issues/8617)

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
kshokhin 2024-06-05 22:42:51 +03:00 committed by GitHub
parent 428c143fbb
commit c7c19609b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 818 additions and 69 deletions

View file

@ -39,8 +39,9 @@ pub struct SearchOptions {
pub case: bool,
pub word: bool,
pub regex: bool,
/// Specifies whether the item supports search & replace.
/// Specifies whether the supports search & replace.
pub replacement: bool,
pub selection: bool,
}
pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
@ -52,15 +53,18 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
word: true,
regex: true,
replacement: true,
selection: true,
}
}
fn search_bar_visibility_changed(&mut self, _visible: bool, _cx: &mut ViewContext<Self>) {}
fn has_filtered_search_ranges(&mut self) -> bool {
false
Self::supported_options().selection
}
fn toggle_filtered_search_ranges(&mut self, _enabled: bool, _cx: &mut ViewContext<Self>) {}
fn clear_matches(&mut self, cx: &mut ViewContext<Self>);
fn update_matches(&mut self, matches: &[Self::Match], cx: &mut ViewContext<Self>);
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String;
@ -138,6 +142,8 @@ pub trait SearchableItemHandle: ItemHandle {
cx: &mut WindowContext,
) -> Option<usize>;
fn search_bar_visibility_changed(&self, visible: bool, cx: &mut WindowContext);
fn toggle_filtered_search_ranges(&mut self, enabled: bool, cx: &mut WindowContext);
}
impl<T: SearchableItem> SearchableItemHandle for View<T> {
@ -240,6 +246,12 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
this.search_bar_visibility_changed(visible, cx)
});
}
fn toggle_filtered_search_ranges(&mut self, enabled: bool, cx: &mut WindowContext) {
self.update(cx, |this, cx| {
this.toggle_filtered_search_ranges(enabled, cx)
});
}
}
impl From<Box<dyn SearchableItemHandle>> for AnyView {