From 1c2f549c82af371a872059b2211083f61166c68c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 7 May 2021 14:30:40 +0200 Subject: [PATCH] Don't report folds that touch the endpoints of the given range Fold ranges are exclusive, exactly like the query ranges. So if the end of a fold coincides with the start of the query range, we shouldn't report that fold. Analogously, if the start of a fold coincides with the end of the query range, that fold shouldn't be reported. --- zed/src/editor/display_map/fold_map.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zed/src/editor/display_map/fold_map.rs b/zed/src/editor/display_map/fold_map.rs index c64d48d12d930d7d05f0a5bf0b424006801911aa..a14a0a5bbb26b092b680800c62a01f1833023cbc 100644 --- a/zed/src/editor/display_map/fold_map.rs +++ b/zed/src/editor/display_map/fold_map.rs @@ -192,8 +192,8 @@ impl FoldMap { let start = buffer.anchor_before(range.start.to_offset(buffer)?)?; let end = buffer.anchor_after(range.end.to_offset(buffer)?)?; Ok(self.folds.filter::<_, usize>(move |summary| { - start.cmp(&summary.max_end, buffer).unwrap() <= Ordering::Equal - && end.cmp(&summary.min_start, buffer).unwrap() >= Ordering::Equal + start.cmp(&summary.max_end, buffer).unwrap() == Ordering::Less + && end.cmp(&summary.min_start, buffer).unwrap() == Ordering::Greater })) } @@ -712,7 +712,7 @@ mod tests { }); assert_eq!(map.text(app.as_ref()), "123a…c123456eee"); - map.unfold(Some(Point::new(0, 4)..Point::new(0, 4)), app.as_ref()) + map.unfold(Some(Point::new(0, 4)..Point::new(0, 5)), app.as_ref()) .unwrap(); assert_eq!(map.text(app.as_ref()), "123aaaaa\nbbbbbb\nccc123456eee"); }); @@ -833,7 +833,6 @@ mod tests { fold_ranges, vec![ Point::new(0, 2)..Point::new(2, 2), - Point::new(0, 4)..Point::new(1, 0), Point::new(1, 2)..Point::new(3, 2) ] ); @@ -1007,9 +1006,10 @@ mod tests { .items() .into_iter() .filter(|fold| { - let fold_start = fold.0.start.to_offset(buffer).unwrap(); - let fold_end = fold.0.end.to_offset(buffer).unwrap(); - start <= fold_end && end >= fold_start + let start = buffer.anchor_before(start).unwrap(); + let end = buffer.anchor_after(end).unwrap(); + start.cmp(&fold.0.end, buffer).unwrap() == Ordering::Less + && end.cmp(&fold.0.start, buffer).unwrap() == Ordering::Greater }) .map(|fold| fold.0) .collect::>();