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.
This commit is contained in:
Max Brunsfeld 2021-12-15 17:29:15 -08:00
parent e8570b5c26
commit f898dc6dae

View file

@ -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)