mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 11:29:25 +00:00
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:
parent
e8570b5c26
commit
f898dc6dae
1 changed files with 6 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue