diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index b802b28360..6ac123ea1e 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -127,14 +127,16 @@ fn search(workspace: &mut Workspace, action: &Search, cx: &mut ViewContext find. fn search_deploy(_: &mut Workspace, _: &buffer_search::Deploy, cx: &mut ViewContext) { - Vim::update(cx, |vim, _| vim.workspace_state.search = Default::default()); + Vim::update(cx, |vim, _| { + vim.update_state(|state| state.search = Default::default()) + }); cx.propagate(); } @@ -154,27 +158,32 @@ fn search_submit(workspace: &mut Workspace, _: &SearchSubmit, cx: &mut ViewConte pane.update(cx, |pane, cx| { if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { search_bar.update(cx, |search_bar, cx| { - let state = &mut vim.workspace_state.search; - let mut count = state.count; - let direction = state.direction; + let (mut prior_selections, prior_mode, prior_operator) = + vim.update_state(|state| { + let mut count = state.search.count; + let direction = state.search.direction; + // in the case that the query has changed, the search bar + // will have selected the next match already. + if (search_bar.query(cx) != state.search.initial_query) + && state.search.direction == Direction::Next + { + count = count.saturating_sub(1) + } + state.search.count = 1; + search_bar.select_match(direction, count, cx); + search_bar.focus_editor(&Default::default(), cx); + + let prior_selections: Vec<_> = + state.search.prior_selections.drain(..).collect(); + let prior_mode = state.search.prior_mode; + let prior_operator = state.search.prior_operator.take(); + (prior_selections, prior_mode, prior_operator) + }); - // in the case that the query has changed, the search bar - // will have selected the next match already. - if (search_bar.query(cx) != state.initial_query) - && state.direction == Direction::Next - { - count = count.saturating_sub(1) - } vim.workspace_state .registers .insert('/', search_bar.query(cx).into()); - state.count = 1; - search_bar.select_match(direction, count, cx); - search_bar.focus_editor(&Default::default(), cx); - let mut prior_selections: Vec<_> = state.prior_selections.drain(..).collect(); - let prior_mode = state.prior_mode; - let prior_operator = state.prior_operator.take(); let new_selections = vim.editor_selections(cx); // If the active editor has changed during a search, don't panic. diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index a22f3bd820..eef88e297b 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -93,6 +93,7 @@ pub struct EditorState { pub undo_modes: HashMap, pub selected_register: Option, + pub search: SearchState, } #[derive(Default, Clone, Debug)] @@ -152,7 +153,6 @@ impl From for Register { #[derive(Default, Clone)] pub struct WorkspaceState { - pub search: SearchState, pub last_find: Option, pub recording: bool,