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
171171 pub regex: bool,
172172 }
173173
174−#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
175−pub 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−
182−impl 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−
195174 #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
196175 pub struct EditorSettingsContent {
197176 /// 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
99 use collections::HashMap;
1010 use editor::{
1111 actions::{Tab, TabPrev},
12− DisplayPoint, Editor, EditorElement, EditorSettings, EditorStyle, SearchSettings,
12+ DisplayPoint, Editor, EditorElement, EditorSettings, EditorStyle,
1313 };
1414 use futures::channel::oneshot;
1515 use gpui::{
@@ -22,7 +22,7 @@ use project::{ · 6 unmodified lines
2222 search_history::{SearchHistory, SearchHistoryCursor},
2323 };
2424 use serde::Deserialize;
25−use settings::{Settings, SettingsStore};
25+use settings::Settings;
2626 use std::sync::Arc;
2727 use theme::ThemeSettings;
2828
@@ -96,7 +96,6 @@ pub struct BufferSearchBar { · 67 unmodified lines
9696 scroll_handle: ScrollHandle,
9797 editor_scroll_handle: ScrollHandle,
9898 editor_needed_width: Pixels,
99− _subscriptions: Vec<Subscription>,
10099 }
101100
102101 impl BufferSearchBar {
@@ -506,11 +505,7 @@ impl BufferSearchBar { · 403 unmodified lines
506505 cx.subscribe(&replacement_editor, Self::on_replacement_editor_event)
507506 .detach();
508507
509− let search_options = SearchOptions::from_settings(&SearchSettings::get_global(cx));
510−
511− let settings_subscription = cx.observe_global::<SettingsStore>(move |this, cx| {
512− this.default_options = SearchOptions::from_settings(&SearchSettings::get_global(cx));
513− });
508+ let search_options = SearchOptions::from_settings(&EditorSettings::get_global(cx).search);
514509
515510 Self {
516511 query_editor,
@@ -537,7 +532,6 @@ impl BufferSearchBar { · 20 unmodified lines
537532 scroll_handle: ScrollHandle::new(),
538533 editor_scroll_handle: ScrollHandle::new(),
539534 editor_needed_width: px(0.),
540− _subscriptions: vec![settings_subscription],
541535 }
542536 }
543537
@@ -610,6 +604,9 @@ impl BufferSearchBar { · 66 unmodified lines
610604 let Some(handle) = self.active_searchable_item.as_ref() else {
611605 return false;
612606 };
607+
608+ self.default_options = SearchOptions::from_settings(&EditorSettings::get_global(cx).search);
609+
613610 if self.default_options != self.search_options {
614611 self.search_options = self.default_options;
615612 }
crates/search/src/search.rs+0−2
@@ -4,7 +4,6 @@ use editor::SearchSettings; · 3 unmodified lines
44 use gpui::{actions, Action, AppContext, IntoElement};
55 use project::search::SearchQuery;
66 pub use project_search::ProjectSearchView;
7−use settings::Settings;
87 use ui::{prelude::*, Tooltip};
98 use ui::{ButtonStyle, IconButton};
109 use workspace::notifications::NotificationId;
@@ -15,7 +14,6 @@ pub mod project_search; · 4 unmodified lines
1514 pub(crate) mod search_bar;
1615
1716 pub fn init(cx: &mut AppContext) {
18− SearchSettings::register(cx);
1917 menu::init();
2018 buffer_search::init(cx);
2119 project_search::init(cx);