# Make \`Buffer::edit\` and \`MultiBuffer::edit\` resilient to inverted ranges · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/8826ad5ddd9dd86f48729334cf569b33a7c6e7c6)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 8826ad5ddd9dd86f48729334cf569b33a7c6e7c6

Requested commit: 8826ad5ddd9dd86f48729334cf569b33a7c6e7c6

Commit: 8826ad5ddd9dd86f48729334cf569b33a7c6e7c6

Tree: 919b135e3b36c82fef55d22423035bf185fe2411

Author: Antonio Scandurra

Committer: Antonio Scandurra

## Message

```
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.

```

## Parents

- [939020a6520dbecb855ae1798456dadd7f5d20f7](https://git.cafe/gitcafe/zed/commit/939020a6520dbecb855ae1798456dadd7f5d20f7?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/8826ad5ddd9dd86f48729334cf569b33a7c6e7c6?format=markdown)
