From c53554ead3cd8843ac316e1f5fb4c1c201330dd8 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:42:11 +0200 Subject: [PATCH] Remove SearchOptions::REGEX. A bit WIP as it awaits migration of buffer search to modes --- crates/search/src/buffer_search.rs | 6 +++--- crates/search/src/mode.rs | 2 +- crates/search/src/project_search.rs | 12 ++---------- crates/search/src/search.rs | 2 -- crates/vim/src/normal/search.rs | 2 +- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 52dd943625..d7b8ab1410 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -209,12 +209,12 @@ impl View for BufferSearchBar { SearchOptions::WHOLE_WORD, cx, )) - .with_children(self.render_search_option( + /*.with_children(self.render_search_option( supported_options.regex, "Regex", SearchOptions::REGEX, cx, - )) + ))*/ .contained() .with_style(theme.search.option_button_group) .aligned(), @@ -697,7 +697,7 @@ impl BufferSearchBar { active_searchable_item.clear_matches(cx); let _ = done_tx.send(()); } else { - let query = if self.search_options.contains(SearchOptions::REGEX) { + let query = if true { match SearchQuery::regex( query, self.search_options.contains(SearchOptions::WHOLE_WORD), diff --git a/crates/search/src/mode.rs b/crates/search/src/mode.rs index b27365b8ed..aaaebc6e86 100644 --- a/crates/search/src/mode.rs +++ b/crates/search/src/mode.rs @@ -2,7 +2,7 @@ use gpui::Action; use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode}; // TODO: Update the default search mode to get from config -#[derive(Copy, Clone, Default, PartialEq)] +#[derive(Copy, Clone, Debug, Default, PartialEq)] pub(crate) enum SearchMode { #[default] Text, diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 5fed36994a..ef905fa8e7 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -736,15 +736,9 @@ impl ProjectSearchView { }).detach_and_log_err(cx); } SearchMode::Regex => { - if !self.is_option_enabled(SearchOptions::REGEX) { - self.toggle_search_option(SearchOptions::REGEX); - } self.semantic_state = None; } SearchMode::Text => { - if self.is_option_enabled(SearchOptions::REGEX) { - self.toggle_search_option(SearchOptions::REGEX); - } self.semantic_state = None; } } @@ -992,7 +986,7 @@ impl ProjectSearchView { return None; } }; - if self.search_options.contains(SearchOptions::REGEX) { + if self.current_mode == SearchMode::Regex { match SearchQuery::regex( text, self.search_options.contains(SearchOptions::WHOLE_WORD), @@ -1011,6 +1005,7 @@ impl ProjectSearchView { } } } else { + debug_assert_ne!(self.current_mode, SearchMode::Semantic); Some(SearchQuery::text( text, self.search_options.contains(SearchOptions::WHOLE_WORD), @@ -1139,9 +1134,6 @@ impl ProjectSearchView { cx.propagate_action(); } - fn is_option_enabled(&self, option: SearchOptions) -> bool { - self.search_options.contains(option) - } } impl Default for ProjectSearchBar { diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 3a985bbe8d..b2cc43c7c1 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -39,7 +39,6 @@ bitflags! { const NONE = 0b000; const WHOLE_WORD = 0b001; const CASE_SENSITIVE = 0b010; - const REGEX = 0b100; } } @@ -68,7 +67,6 @@ impl SearchOptions { let mut options = SearchOptions::NONE; options.set(SearchOptions::WHOLE_WORD, query.whole_word()); options.set(SearchOptions::CASE_SENSITIVE, query.case_sensitive()); - options.set(SearchOptions::REGEX, query.is_regex()); options } } diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 9375c4e78d..2ec4162e1e 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -66,7 +66,7 @@ fn search(workspace: &mut Workspace, action: &Search, cx: &mut ViewContext