From a8a402e5ac2c161e1f083ce7d161f93c27a14eaa Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 20:45:16 -0600 Subject: [PATCH] Fix panic in vim search (cherry-pick #11022) (#11031) Cherry-picked Fix panic in vim search (#11022) Release Notes: - vim: Fixed a panic when searching Co-authored-by: Conrad Irwin --- crates/vim/src/normal/search.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 16ac5c009049f829138ebfb23e5d6e4d49b0971d..b2670ffdbcacaa6b3ec2419ae3db3323c6304ca7 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -159,11 +159,21 @@ fn search_submit(workspace: &mut Workspace, _: &SearchSubmit, cx: &mut ViewConte search_bar.select_match(direction, count, cx); search_bar.focus_editor(&Default::default(), cx); - let prior_selections = state.prior_selections.drain(..).collect(); + 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. + if prior_selections.iter().any(|s| { + vim.update_active_editor(cx, |_vim, editor, cx| { + !s.start.is_valid(&editor.snapshot(cx).buffer_snapshot) + }) + .unwrap_or(true) + }) { + prior_selections.clear(); + } + if prior_mode != vim.state().mode { vim.switch_mode(prior_mode, true, cx); }