Fix after new settings

Conrad Irwin and dino created

Co-Authored-By: dino <dinojoaocosta@gmail.com>

Change summary

crates/editor/src/editor.rs          | 16 --------
crates/editor/src/editor_settings.rs |  1 
crates/vim/src/command.rs            | 60 ++++++++++++++++++++++++++++-
3 files changed, 57 insertions(+), 20 deletions(-)

Detailed changes

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<Self>) {
-        let Some(workspace) = self.workspace() else {
-            return;
-        };
-
-        let fs = workspace.read(cx).app_state().fs.clone();
-        update_settings_file::<SearchSettings>(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>) {
         self.show_gutter = show_gutter;
         cx.notify();

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;

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<Vim>) {
                     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`."
+            );
+        });
+    }
 }