From c015baa6385202af1a965c6346af71426c7e377e Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 14 Mar 2024 15:06:00 +0100 Subject: [PATCH] Do not start searching if query is empty (#9333) This avoids the problem of a search being kicked off involuntarily and potentially using a large amount of CPU when toggling on the `Search Ignored Files` option. What would happen is that someone would turn the option on, we'd kick off a search, and go through all of the files in, say, `node_modules`. Even if no query was given. This avoids that. Release Notes: - Fixed an empty search being kicked off involuntarily if no query was typed in yet but an option was toggled. --- crates/project/src/search.rs | 4 ++++ crates/search/src/project_search.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs index bfbc537b27e92821a02e401ccf05a7cd013fb2b7..4b872aa5558f82e5425f016e107f29a6e8630b00 100644 --- a/crates/project/src/search.rs +++ b/crates/project/src/search.rs @@ -327,6 +327,10 @@ impl SearchQuery { matches } + pub fn is_empty(&self) -> bool { + self.as_str().is_empty() + } + pub fn as_str(&self) -> &str { self.as_inner().as_str() } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index b9b7d95218806e9a4bbfa84720cb4f284bd3db12..57297409586f1d79e3974718b25e783c47b157bd 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1231,6 +1231,9 @@ impl ProjectSearchView { if !self.panels_with_errors.is_empty() { return None; } + if query.as_ref().is_some_and(|query| query.is_empty()) { + return None; + } query }