History

Refactor SearchSettings (#17550)

Related to #17179. Simplify handling of search settings since there is no requirement to watch for settings.json changes and update search panels while they are opened. Attn: @SomeoneToIgnore Per our discussion. Ran test on search crate. Ran `cargo fmt`. Release Notes: - N/A

thataboy committed 2 years ago

Commit 894866d1 parent 63188b63 files · +6 −32Browse files

Unified · Split

3 files
  1. crates/editor/src/editor_settings.rs +0 −21
  2. crates/search/src/buffer_search.rs +6 −9
  3. crates/search/src/search.rs +0 −2
crates/editor/src/editor_settings.rs+0−21
@@ -171,27 +171,6 @@ pub struct SearchSettings { · 170 unmodified lines
171 pub regex: bool,171 pub regex: bool,
172}172}
173 173
174#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
175pub struct SearchSettingsContent {
176 pub whole_word: Option<bool>,
177 pub case_sensitive: Option<bool>,
178 pub include_ignored: Option<bool>,
179 pub regex: Option<bool>,
180}
181
182impl Settings for SearchSettings {
183 const KEY: Option<&'static str> = Some("search");
184
185 type FileContent = SearchSettingsContent;
186
187 fn load(
188 sources: SettingsSources<Self::FileContent>,
189 _: &mut gpui::AppContext,
190 ) -> anyhow::Result<Self> {
191 sources.json_merge()
192 }
193}
194
195#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]174#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
196pub struct EditorSettingsContent {175pub struct EditorSettingsContent {
197 /// Whether the cursor blinks in the editor.176 /// Whether the cursor blinks in the editor.
crates/search/src/buffer_search.rs+6−9
@@ -9,7 +9,7 @@ use any_vec::AnyVec; · 8 unmodified lines
9use collections::HashMap;9use collections::HashMap;
10use editor::{10use editor::{
11 actions::{Tab, TabPrev},11 actions::{Tab, TabPrev},
12 DisplayPoint, Editor, EditorElement, EditorSettings, EditorStyle, SearchSettings,12 DisplayPoint, Editor, EditorElement, EditorSettings, EditorStyle,
13};13};
14use futures::channel::oneshot;14use futures::channel::oneshot;
15use gpui::{15use gpui::{
@@ -22,7 +22,7 @@ use project::{ · 6 unmodified lines
22 search_history::{SearchHistory, SearchHistoryCursor},22 search_history::{SearchHistory, SearchHistoryCursor},
23};23};
24use serde::Deserialize;24use serde::Deserialize;
25use settings::{Settings, SettingsStore};25use settings::Settings;
26use std::sync::Arc;26use std::sync::Arc;
27use theme::ThemeSettings;27use theme::ThemeSettings;
28 28
@@ -96,7 +96,6 @@ pub struct BufferSearchBar { · 67 unmodified lines
96 scroll_handle: ScrollHandle,96 scroll_handle: ScrollHandle,
97 editor_scroll_handle: ScrollHandle,97 editor_scroll_handle: ScrollHandle,
98 editor_needed_width: Pixels,98 editor_needed_width: Pixels,
99 _subscriptions: Vec<Subscription>,
100}99}
101 100
102impl BufferSearchBar {101impl BufferSearchBar {
@@ -506,11 +505,7 @@ impl BufferSearchBar { · 403 unmodified lines
506 cx.subscribe(&replacement_editor, Self::on_replacement_editor_event)505 cx.subscribe(&replacement_editor, Self::on_replacement_editor_event)
507 .detach();506 .detach();
508 507
509 let search_options = SearchOptions::from_settings(&SearchSettings::get_global(cx));508 let search_options = SearchOptions::from_settings(&EditorSettings::get_global(cx).search);
510
511 let settings_subscription = cx.observe_global::<SettingsStore>(move |this, cx| {
512 this.default_options = SearchOptions::from_settings(&SearchSettings::get_global(cx));
513 });
514 509
515 Self {510 Self {
516 query_editor,511 query_editor,
@@ -537,7 +532,6 @@ impl BufferSearchBar { · 20 unmodified lines
537 scroll_handle: ScrollHandle::new(),532 scroll_handle: ScrollHandle::new(),
538 editor_scroll_handle: ScrollHandle::new(),533 editor_scroll_handle: ScrollHandle::new(),
539 editor_needed_width: px(0.),534 editor_needed_width: px(0.),
540 _subscriptions: vec![settings_subscription],
541 }535 }
542 }536 }
543 537
@@ -610,6 +604,9 @@ impl BufferSearchBar { · 66 unmodified lines
610 let Some(handle) = self.active_searchable_item.as_ref() else {604 let Some(handle) = self.active_searchable_item.as_ref() else {
611 return false;605 return false;
612 };606 };
607
608 self.default_options = SearchOptions::from_settings(&EditorSettings::get_global(cx).search);
609
613 if self.default_options != self.search_options {610 if self.default_options != self.search_options {
614 self.search_options = self.default_options;611 self.search_options = self.default_options;
615 }612 }
crates/search/src/search.rs+0−2
@@ -4,7 +4,6 @@ use editor::SearchSettings; · 3 unmodified lines
4use gpui::{actions, Action, AppContext, IntoElement};4use gpui::{actions, Action, AppContext, IntoElement};
5use project::search::SearchQuery;5use project::search::SearchQuery;
6pub use project_search::ProjectSearchView;6pub use project_search::ProjectSearchView;
7use settings::Settings;
8use ui::{prelude::*, Tooltip};7use ui::{prelude::*, Tooltip};
9use ui::{ButtonStyle, IconButton};8use ui::{ButtonStyle, IconButton};
10use workspace::notifications::NotificationId;9use workspace::notifications::NotificationId;
@@ -15,7 +14,6 @@ pub mod project_search; · 4 unmodified lines
15pub(crate) mod search_bar;14pub(crate) mod search_bar;
16 15
17pub fn init(cx: &mut AppContext) {16pub fn init(cx: &mut AppContext) {
18 SearchSettings::register(cx);
19 menu::init();17 menu::init();
20 buffer_search::init(cx);18 buffer_search::init(cx);
21 project_search::init(cx);19 project_search::init(cx);