Guard against inverted ranges when building edits in unfold

Max Brunsfeld created

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.

Change summary

crates/editor/src/display_map/fold_map.rs | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

Detailed changes

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)