From fecea03c90a1160c883834b59ac7625185d9cf65 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:25:32 +0200 Subject: [PATCH] Add modes to buffer search --- crates/search/src/buffer_search.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index d7b8ab14102b2da5be463615646bf5a032340d02..8823f8236eb2d53580872ee52f8584b5854b6d4b 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1,6 +1,7 @@ use crate::{ - history::SearchHistory, NextHistoryQuery, PreviousHistoryQuery, SearchOptions, - SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, + history::SearchHistory, mode::SearchMode, search_bar::render_search_mode_button, + NextHistoryQuery, PreviousHistoryQuery, SearchOptions, SelectAllMatches, SelectNextMatch, + SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, }; use collections::HashMap; use editor::Editor; @@ -78,6 +79,7 @@ pub struct BufferSearchBar { query_contains_error: bool, dismissed: bool, search_history: SearchHistory, + current_mode: SearchMode, } impl Entity for BufferSearchBar { @@ -149,7 +151,18 @@ impl View for BufferSearchBar { self.query_editor.update(cx, |editor, cx| { editor.set_placeholder_text(new_placeholder_text, cx); }); + let search_button_for_mode = |mode, cx: &mut ViewContext| { + let is_active = self.current_mode == mode; + render_search_mode_button( + mode, + is_active, + move |_, this, cx| { + //this.activate_search_mode(mode, cx); + }, + cx, + ) + }; Flex::row() .with_child( Flex::row() @@ -221,6 +234,8 @@ impl View for BufferSearchBar { ) .flex(1., true), ) + .with_child(search_button_for_mode(SearchMode::Text, cx)) + .with_child(search_button_for_mode(SearchMode::Regex, cx)) .with_child(super::search_bar::render_close_button( &theme.search, cx, @@ -308,6 +323,7 @@ impl BufferSearchBar { query_contains_error: false, dismissed: true, search_history: SearchHistory::default(), + current_mode: SearchMode::default(), } }