From 894866da9478003e77458e7a849353312d4c282c Mon Sep 17 00:00:00 2001 From: thataboy Date: Sat, 7 Sep 2024 16:58:28 -0700 Subject: [PATCH] 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 --- crates/editor/src/editor_settings.rs | 21 --------------------- crates/search/src/buffer_search.rs | 15 ++++++--------- crates/search/src/search.rs | 2 -- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 8dadc0154bd0c2a03edd6e5636ead8fe3b809302..2614e4ea303d244e47a487837cb9e7aa2f10683b 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -171,27 +171,6 @@ pub struct SearchSettings { pub regex: bool, } -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)] -pub struct SearchSettingsContent { - pub whole_word: Option, - pub case_sensitive: Option, - pub include_ignored: Option, - pub regex: Option, -} - -impl Settings for SearchSettings { - const KEY: Option<&'static str> = Some("search"); - - type FileContent = SearchSettingsContent; - - fn load( - sources: SettingsSources, - _: &mut gpui::AppContext, - ) -> anyhow::Result { - sources.json_merge() - } -} - #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] pub struct EditorSettingsContent { /// Whether the cursor blinks in the editor. diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index ba10a45282fb24111dbf545fc269c56da6af047a..3a7cccfbb916c90925544cc50cdd1638519ae13a 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -9,7 +9,7 @@ use any_vec::AnyVec; use collections::HashMap; use editor::{ actions::{Tab, TabPrev}, - DisplayPoint, Editor, EditorElement, EditorSettings, EditorStyle, SearchSettings, + DisplayPoint, Editor, EditorElement, EditorSettings, EditorStyle, }; use futures::channel::oneshot; use gpui::{ @@ -22,7 +22,7 @@ use project::{ search_history::{SearchHistory, SearchHistoryCursor}, }; use serde::Deserialize; -use settings::{Settings, SettingsStore}; +use settings::Settings; use std::sync::Arc; use theme::ThemeSettings; @@ -96,7 +96,6 @@ pub struct BufferSearchBar { scroll_handle: ScrollHandle, editor_scroll_handle: ScrollHandle, editor_needed_width: Pixels, - _subscriptions: Vec, } impl BufferSearchBar { @@ -506,11 +505,7 @@ impl BufferSearchBar { cx.subscribe(&replacement_editor, Self::on_replacement_editor_event) .detach(); - let search_options = SearchOptions::from_settings(&SearchSettings::get_global(cx)); - - let settings_subscription = cx.observe_global::(move |this, cx| { - this.default_options = SearchOptions::from_settings(&SearchSettings::get_global(cx)); - }); + let search_options = SearchOptions::from_settings(&EditorSettings::get_global(cx).search); Self { query_editor, @@ -537,7 +532,6 @@ impl BufferSearchBar { scroll_handle: ScrollHandle::new(), editor_scroll_handle: ScrollHandle::new(), editor_needed_width: px(0.), - _subscriptions: vec![settings_subscription], } } @@ -610,6 +604,9 @@ impl BufferSearchBar { let Some(handle) = self.active_searchable_item.as_ref() else { return false; }; + + self.default_options = SearchOptions::from_settings(&EditorSettings::get_global(cx).search); + if self.default_options != self.search_options { self.search_options = self.default_options; } diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index f8d8da87c5b88da52dedb05b44b57ba9470089b5..b99672c532d6bbb10851114c0b10efda7ee329db 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -4,7 +4,6 @@ use editor::SearchSettings; use gpui::{actions, Action, AppContext, IntoElement}; use project::search::SearchQuery; pub use project_search::ProjectSearchView; -use settings::Settings; use ui::{prelude::*, Tooltip}; use ui::{ButtonStyle, IconButton}; use workspace::notifications::NotificationId; @@ -15,7 +14,6 @@ pub mod project_search; pub(crate) mod search_bar; pub fn init(cx: &mut AppContext) { - SearchSettings::register(cx); menu::init(); buffer_search::init(cx); project_search::init(cx);