vim search: remember settings

Michael Benfield created

In particular, don't do anything special for REGEX or
CASE_SENSITIVE; just let the regular settings handle that.

Don't let BACKWARDS stick around in the buffer search settings -
otherwise if the last vim search is BACKWARDS, the next Ctrl+F search
will be too.

Closes #21956

Change summary

crates/search/src/buffer_search.rs |  7 +++++++
crates/vim/src/normal/search.rs    | 17 ++++++-----------
2 files changed, 13 insertions(+), 11 deletions(-)

Detailed changes

crates/search/src/buffer_search.rs 🔗

@@ -786,6 +786,9 @@ impl BufferSearchBar {
             self.default_options = configured_options;
         }
 
+        // This isn't a normal setting; it's only applicable to vim search.
+        self.search_options.remove(SearchOptions::BACKWARDS);
+
         self.dismissed = false;
         self.adjust_query_regex_language(cx);
         handle.search_bar_visibility_changed(true, window, cx);
@@ -958,6 +961,10 @@ impl BufferSearchBar {
         Some(self.update_matches(false, false, window, cx))
     }
 
+    pub fn search_options(&self) -> SearchOptions {
+        self.search_options
+    }
+
     pub fn set_search_options(&mut self, search_options: SearchOptions, cx: &mut Context<Self>) {
         self.search_options = search_options;
         self.adjust_query_regex_language(cx);

crates/vim/src/normal/search.rs 🔗

@@ -49,8 +49,6 @@ pub(crate) struct MoveToPrevious {
 pub(crate) struct Search {
     #[serde(default)]
     backwards: bool,
-    #[serde(default = "default_true")]
-    regex: bool,
 }
 
 /// Executes a find command to search for patterns in the buffer.
@@ -99,6 +97,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
     Vim::action(editor, cx, Vim::move_to_previous_match);
     Vim::action(editor, cx, Vim::search);
     Vim::action(editor, cx, Vim::search_deploy);
+
     Vim::action(editor, cx, Vim::find_command);
     Vim::action(editor, cx, Vim::replace_command);
 }
@@ -172,17 +171,13 @@ impl Vim {
                     cx.focus_self(window);
 
                     search_bar.set_replacement(None, cx);
-                    let mut options = SearchOptions::NONE;
-                    if action.regex {
-                        options |= SearchOptions::REGEX;
-                    }
                     if action.backwards {
-                        options |= SearchOptions::BACKWARDS;
-                    }
-                    if EditorSettings::get_global(cx).search.case_sensitive {
-                        options |= SearchOptions::CASE_SENSITIVE;
+                        search_bar.set_search_options(
+                            search_bar.search_options() | SearchOptions::BACKWARDS,
+                            cx,
+                        );
                     }
-                    search_bar.set_search_options(options, cx);
+
                     let prior_mode = if self.temp_mode {
                         Mode::Insert
                     } else {