Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Finish migration to modes for buffer search
Piotr Osiewicz343e9d080ed1
diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rsindex 8823f8236eb..758a0b17cf3 100644--- a/crates/search/src/buffer_search.rs+++ b/crates/search/src/buffer_search.rs@@ -158,7 +158,7 @@ impl View for BufferSearchBar {mode,is_active,move |_, this, cx| {- //this.activate_search_mode(mode, cx);+ this.activate_search_mode(mode, cx);},cx,)@@ -222,12 +222,6 @@ impl View for BufferSearchBar {SearchOptions::WHOLE_WORD,cx,))- /*.with_children(self.render_search_option(- supported_options.regex,- "Regex",- SearchOptions::REGEX,- cx,- ))*/.contained().with_style(theme.search.option_button_group).aligned(),@@ -537,7 +531,19 @@ impl BufferSearchBar {).into_any()}-+ pub fn activate_search_mode(&mut self, mode: SearchMode, cx: &mut ViewContext<Self>) {+ assert_ne!(+ mode,+ SearchMode::Semantic,+ "Semantic search is not supported in buffer search"+ );+ if mode == self.current_mode {+ return;+ }+ self.current_mode = mode;+ let _ = self.update_matches(cx);+ cx.notify();+ }fn deploy(pane: &mut Pane, action: &Deploy, cx: &mut ViewContext<Pane>) {let mut propagate_action = true;if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {@@ -713,7 +719,7 @@ impl BufferSearchBar {active_searchable_item.clear_matches(cx);let _ = done_tx.send(());} else {- let query = if true {+ let query = if self.current_mode == SearchMode::Regex {match SearchQuery::regex(query,self.search_options.contains(SearchOptions::WHOLE_WORD),diff --git a/crates/search/src/mode.rs b/crates/search/src/mode.rsindex 072b9ffd804..bb620f0670b 100644--- a/crates/search/src/mode.rs+++ b/crates/search/src/mode.rs@@ -3,7 +3,7 @@ use gpui::Action;use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode};// TODO: Update the default search mode to get from config#[derive(Copy, Clone, Debug, Default, PartialEq)]-pub(crate) enum SearchMode {+pub enum SearchMode {#[default]Text,Semantic,diff --git a/crates/search/src/search.rs b/crates/search/src/search.rsindex b2cc43c7c16..33905f83ece 100644--- a/crates/search/src/search.rs+++ b/crates/search/src/search.rs@@ -1,6 +1,7 @@use bitflags::bitflags;pub use buffer_search::BufferSearchBar;use gpui::{actions, Action, AppContext};+pub use mode::SearchMode;use project::search::SearchQuery;pub use project_search::{ProjectSearchBar, ProjectSearchView};diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rsindex 2ec4162e1e1..5f1a68cfe96 100644--- a/crates/vim/src/normal/search.rs+++ b/crates/vim/src/normal/search.rs@@ -1,5 +1,5 @@use gpui::{actions, impl_actions, AppContext, ViewContext};-use search::{buffer_search, BufferSearchBar, SearchOptions};+use search::{buffer_search, BufferSearchBar, SearchMode, SearchOptions};use serde_derive::Deserialize;use workspace::{searchable::Direction, Pane, Workspace};@@ -65,10 +65,8 @@ fn search(workspace: &mut Workspace, action: &Search, cx: &mut ViewContext<Workscx.focus_self();if query.is_empty() {- search_bar.set_search_options(- SearchOptions::CASE_SENSITIVE, // | SearchOptions::REGEX,- cx,- );+ search_bar.set_search_options(SearchOptions::CASE_SENSITIVE, cx);+ search_bar.activate_search_mode(SearchMode::Regex, cx);}vim.state.search = SearchState {direction,