Make Buffer::edit and MultiBuffer::edit resilient to inverted ranges

Previously, we would accept edits containing out-of-order ranges. When
generating such ranges in our randomized tests, many invariants started
breaking causing e.g. undo/redo to misbehave and operation application
to panic.

In theory, we should never pass inverted ranges, but this commit changes
the above functions to swap the start and the end when that occurs to avoid
breaking the entire system and panicking.
This commit is contained in:
Antonio Scandurra 2022-06-06 15:15:50 +02:00
parent 939020a652
commit 8826ad5ddd
3 changed files with 55 additions and 25 deletions

View file

@ -693,7 +693,7 @@ pub mod tests {
}
}
_ => {
buffer.update(cx, |buffer, cx| buffer.randomly_edit(&mut rng, 5, cx));
buffer.update(cx, |buffer, cx| buffer.randomly_mutate(&mut rng, 5, cx));
}
}