From a82d7aa2a9b18aa4ad9b9a39bb58564b63010846 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:50:42 -0500 Subject: [PATCH] vim: Fix search submit panic (cherry-pick #25673) (#25717) Cherry-picked vim: Fix search submit panic (#25673) In file search submit action, handle unwrap when there are no prior selection. Release Notes: - vim: Fixed a panic when submitting a search. --------- Co-authored-by: Anthony Eid Co-authored-by: smit <0xtimsb@gmail.com> Co-authored-by: Anthony Eid --- crates/vim/src/normal/search.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 81d2897e59cc21f114d2c99f1394a712a9e53a25..23b5ab3f699b865846009d3c7032c0ea38693f9d 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -187,9 +187,13 @@ impl Vim { let direction = self.search.direction; search_bar.has_active_match(); let new_head = new_selections.last().unwrap().start; - let old_head = self.search.prior_selections.last().unwrap().start; + let is_different_head = self + .search + .prior_selections + .last() + .map_or(true, |range| range.start != new_head); - if new_head != old_head && self.search.direction == Direction::Next { + if is_different_head && self.search.direction == Direction::Next { count = count.saturating_sub(1) } self.search.count = 1;