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.
This commit is contained in:
Thorsten Ball 2024-03-14 15:06:00 +01:00 committed by GitHub
parent f142568172
commit c015baa638
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -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()
}

View File

@ -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
}