# editor: Fix crash when copying and pasting using multiple cursors \(\#61545\) · gitcafe/zed

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

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

Visibility: public

Requested revision: e12992cae3c0405a6e89e7b1190e95e843845c2e

Requested commit: e12992cae3c0405a6e89e7b1190e95e843845c2e

Commit: e12992cae3c0405a6e89e7b1190e95e843845c2e

Tree: 95f72569210eda7a02adedfaf70ee97f9b2466f0

Author: Tim Vermeulen

Committer: GitHub

## Message

````
editor: Fix crash when copying and pasting using multiple cursors (#61545)

Fixes a crash when copying and pasting a mixed empty/nonempty
multi-cursor selection.

`Editor::do_copy` is meant to insert a newline after each non-final
selection that doesn't copy the entire line, but
`prev_selection_was_entire_line` is currently based on the current
selection instead of the previous one. `Editor::cut_common` does already
correctly track this state across loop iterations.

This can lead to an out of bounds crash when pasting because the
indexing logic in `Editor::do_paste` relies on these newlines being
added correctly, depending on `is_entire_line`.

Repro:

```
foo
bar
```
1. select `foo`
2. option-click after `bar` to add an empty selection
```
«fooˇ»
barˇ
```
3. copy
4. paste

## 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 a crash when copying and pasting using multiple cursors.
````

## Parents

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

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