From f898dc6dae3489c52a458994e1875f89c5c84d53 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 15 Dec 2021 17:29:15 -0800 Subject: [PATCH] Guard against inverted ranges when building edits in unfold The multibuffer lets you refer to offsets inside of headers, so it's possible to create a fold that appears non-empty, but which spans zero characters in the underlying buffers. Fold ranges are biased inward: the start is biased right, and the end is biased left. Because of these two things, it's possible to create a fold that becomes "inverted" when you insert text at that position. --- crates/editor/src/display_map/fold_map.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 972e152c18..13e82fe942 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -152,10 +152,12 @@ impl<'a> FoldMapWriter<'a> { let mut folds_cursor = intersecting_folds(&buffer, &self.0.folds, range, true); while let Some(fold) = folds_cursor.item() { let offset_range = fold.0.start.to_offset(&buffer)..fold.0.end.to_offset(&buffer); - edits.push(text::Edit { - old: offset_range.clone(), - new: offset_range, - }); + if offset_range.end > offset_range.start { + edits.push(text::Edit { + old: offset_range.clone(), + new: offset_range, + }); + } fold_ixs_to_delete.push(*folds_cursor.start()); folds_cursor.next(&buffer); } @@ -1366,7 +1368,6 @@ mod tests { } let text = &expected_text[start.0..end.0]; - log::info!("slicing {:?}..{:?} (text: {:?})", start, end, text); assert_eq!( snapshot .chunks(start..end, None)