Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

search: Re-issue project search if search query is stale on replacement (#38251)

Lukas Wirth173074f24852
diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs
index f2c6091e0cb..953fa4f1aaf 100644
--- a/crates/project/src/search.rs
+++ b/crates/project/src/search.rs
@@ -64,7 +64,6 @@ pub enum SearchQuery {
include_ignored: bool,
inner: SearchInputs,
},
-
Regex {
regex: Regex,
replacement: Option<String>,
diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs
index 3d9248e3c7e..eaad5dad65b 100644
--- a/crates/search/src/project_search.rs
+++ b/crates/search/src/project_search.rs
@@ -679,7 +679,18 @@ impl ProjectSearchView {
self.included_opened_only = !self.included_opened_only;
}
+ pub fn replacement(&self, cx: &App) -> String {
+ self.replacement_editor.read(cx).text(cx)
+ }
+
fn replace_next(&mut self, _: &ReplaceNext, window: &mut Window, cx: &mut Context<Self>) {
+ if let Some(last_search_query_text) = &self.entity.read(cx).last_search_query_text
+ && self.query_editor.read(cx).text(cx) != *last_search_query_text
+ {
+ // search query has changed, restart search and bail
+ self.search(cx);
+ return;
+ }
if self.entity.read(cx).match_ranges.is_empty() {
return;
}
@@ -699,14 +710,17 @@ impl ProjectSearchView {
self.select_match(Direction::Next, window, cx)
}
}
- pub fn replacement(&self, cx: &App) -> String {
- self.replacement_editor.read(cx).text(cx)
- }
fn replace_all(&mut self, _: &ReplaceAll, window: &mut Window, cx: &mut Context<Self>) {
+ if let Some(last_search_query_text) = &self.entity.read(cx).last_search_query_text
+ && self.query_editor.read(cx).text(cx) != *last_search_query_text
+ {
+ // search query has changed, restart search and bail
+ self.search(cx);
+ return;
+ }
if self.active_match_index.is_none() {
return;
}
-
let Some(query) = self.entity.read(cx).active_query.as_ref() else {
return;
};