diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a1d1dfa7a19222719120f8980953d8e7c3e0a2ce..9ab7f857dad3d33b2f4eaaa5298dbee8a307f05d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -344,7 +344,6 @@ pub enum HideMouseCursorOrigin { pub fn init_settings(cx: &mut App) { EditorSettings::register(cx); - SearchSettings::register(cx); } pub fn init(cx: &mut App) { @@ -19266,21 +19265,6 @@ impl Editor { cx.notify(); } - /// Controls whether search results should be case-insensitive (`true`) or - /// case-sensitive (`false`). - pub fn set_ignorecase(&mut self, enabled: bool, cx: &mut Context) { - let Some(workspace) = self.workspace() else { - return; - }; - - let fs = workspace.read(cx).app_state().fs.clone(); - update_settings_file::(fs, cx, move |settings, _| { - settings.case_sensitive = Some(!enabled); - }); - - cx.notify(); - } - pub fn set_show_gutter(&mut self, show_gutter: bool, cx: &mut Context) { self.show_gutter = show_gutter; cx.notify(); diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 2a9db63bcb2ea659361ecb95f33b06d5ed0986fa..6ad8304f911a54fc0817f963aa593dc6e908637b 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -1,7 +1,6 @@ use core::num; use std::num::NonZeroU32; -use anyhow::Result; use gpui::App; use language::CursorShape; use project::project_settings::DiagnosticSeverity; diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index bcb4484dfbcd0b210b80c46ff6530fe685252c6b..275432433000b730a6bb88da46c7583aaeffd8b4 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -2,7 +2,7 @@ use anyhow::{Result, anyhow}; use collections::{HashMap, HashSet}; use command_palette_hooks::CommandInterceptResult; use editor::{ - Bias, Editor, SelectionEffects, ToPoint, + Bias, Editor, EditorSettings, SelectionEffects, ToPoint, actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive}, display_map::ToDisplayPoint, }; @@ -16,6 +16,7 @@ use regex::Regex; use schemars::JsonSchema; use search::{BufferSearchBar, SearchOptions}; use serde::Deserialize; +use settings::{Settings, SettingsStore}; use std::{ iter::Peekable, ops::{Deref, Range}, @@ -270,7 +271,11 @@ pub fn register(editor: &mut Editor, cx: &mut Context) { editor.set_relative_line_number(Some(*enabled), cx); } VimOption::IgnoreCase(enabled) => { - editor.set_ignorecase(*enabled, cx); + let mut settings = EditorSettings::get_global(cx).clone(); + settings.search.case_sensitive = !*enabled; + SettingsStore::update(cx, |store, _| { + store.override_global(settings); + }); } }); } @@ -2060,9 +2065,10 @@ mod test { state::Mode, test::{NeovimBackedTestContext, VimTestContext}, }; - use editor::Editor; + use editor::{Editor, EditorSettings}; use gpui::{Context, TestAppContext}; use indoc::indoc; + use settings::Settings; use util::path; use workspace::Workspace; @@ -2620,4 +2626,52 @@ mod test { assert_active_item(workspace, path!("/root/dir/file_3.rs"), "", cx); }); } + + #[gpui::test] + async fn test_ignorecase_command(cx: &mut TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + cx.read(|cx| { + assert_eq!( + EditorSettings::get_global(cx).search.case_sensitive, + false, + "The `case_sensitive` setting should be `false` by default." + ); + }); + cx.simulate_keystrokes(": set space noignorecase"); + cx.simulate_keystrokes("enter"); + cx.read(|cx| { + assert_eq!( + EditorSettings::get_global(cx).search.case_sensitive, + true, + "The `case_sensitive` setting should have been enabled with `:set noignorecase`." + ); + }); + cx.simulate_keystrokes(": set space ignorecase"); + cx.simulate_keystrokes("enter"); + cx.read(|cx| { + assert_eq!( + EditorSettings::get_global(cx).search.case_sensitive, + false, + "The `case_sensitive` setting should have been disabled with `:set ignorecase`." + ); + }); + cx.simulate_keystrokes(": set space noic"); + cx.simulate_keystrokes("enter"); + cx.read(|cx| { + assert_eq!( + EditorSettings::get_global(cx).search.case_sensitive, + true, + "The `case_sensitive` setting should have been enabled with `:set noic`." + ); + }); + cx.simulate_keystrokes(": set space ic"); + cx.simulate_keystrokes("enter"); + cx.read(|cx| { + assert_eq!( + EditorSettings::get_global(cx).search.case_sensitive, + false, + "The `case_sensitive` setting should have been disabled with `:set ic`." + ); + }); + } }