vim: Fix search submit panic (#25673)
smit
and
Anthony Eid
created 1 year ago
In file search submit action, handle unwrap when there are no prior
selection.
Fix is for recently made commits, hence no release notes.
Release Notes:
- N/A
---------
Co-authored-by: Anthony Eid <anthony@zed.dev>
Change summary
crates/vim/src/normal/search.rs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
Detailed changes
@@ -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;