mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
Fix panic when moving to next/prev result but there are no matches
This commit is contained in:
parent
803cdd00a6
commit
eb537214ed
1 changed files with 14 additions and 10 deletions
|
@ -512,17 +512,21 @@ impl FindBar {
|
|||
let editor = editor.read(cx);
|
||||
let position = editor.newest_anchor_selection()?.head();
|
||||
let ranges = editor.highlighted_ranges_for_type::<Self>()?.1;
|
||||
let buffer = editor.buffer().read(cx).read(cx);
|
||||
match ranges.binary_search_by(|probe| {
|
||||
if probe.end.cmp(&position, &*buffer).unwrap().is_lt() {
|
||||
Ordering::Less
|
||||
} else if probe.start.cmp(&position, &*buffer).unwrap().is_gt() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
Ordering::Equal
|
||||
if ranges.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let buffer = editor.buffer().read(cx).read(cx);
|
||||
match ranges.binary_search_by(|probe| {
|
||||
if probe.end.cmp(&position, &*buffer).unwrap().is_lt() {
|
||||
Ordering::Less
|
||||
} else if probe.start.cmp(&position, &*buffer).unwrap().is_gt() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
Ordering::Equal
|
||||
}
|
||||
}) {
|
||||
Ok(i) | Err(i) => Some(cmp::min(i, ranges.len() - 1)),
|
||||
}
|
||||
}) {
|
||||
Ok(i) | Err(i) => Some(cmp::min(i, ranges.len().saturating_sub(1))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue