# Fix crash in \`Editor::rotate_selections\` using cursors on nonconsecutive lines \(\#63937\) · gitcafe/zed

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

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

Visibility: public

Requested revision: ff6a6abbd1788eeee2a76766ef5188ee5a046e61

Requested commit: ff6a6abbd1788eeee2a76766ef5188ee5a046e61

Commit: ff6a6abbd1788eeee2a76766ef5188ee5a046e61

Tree: 278505feb56c3eed0a5016bd362787c27e79d09f

Author: Tim Vermeulen

Committer: GitHub

## Message

````
Fix crash in `Editor::rotate_selections` using cursors on nonconsecutive lines (#63937)

Crash repro:

```
A
1234567890
B
C
```
1. place cursors before `A`, `B`, and `C`
2. run `editor: rotate selections forward`

Caused by the current `Editor::rotate_selections` logic assuming that
the text between the end of one of the lines being rotated and the start
of the next one is just the newline:
```rs
let newline_len = line_ranges[1].start.0 - line_ranges[0].end.0;
```
which fails when those lines aren't consecutive in the editor.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed crash in `editor: rotate selections forward` and `editor: rotate
selections backward` using cursors on nonconsecutive lines.
````

## Parents

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

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