# helix: Fix paste crash \(\#58373\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 1125a45d79c30fe1c894d735455549866d3d7bc4

Requested commit: 1125a45d79c30fe1c894d735455549866d3d7bc4

Commit: 1125a45d79c30fe1c894d735455549866d3d7bc4

Tree: 5c865ffc3b3c113c1cbc93569e880b78278dffc0

Author: Anthony Eid

Committer: GitHub

## Message

```
helix: Fix paste crash (#58373)

Closes [#58343](<https://github.com/zed-industries/zed/issues/58343>)

This crash happened because Helix paste restored selection using the raw
clipboard text length, but buffer edits normalize CRLF line endings to
LF before inserting. When pasting CRLF text at or near EOF, the restored
selection could extend past the normalized snapshot length and panic in
`MutableSelectionsCollection::select_ranges`. The fix normalizes the
text before measuring it for selection restoration and adds regression
coverage for CRLF paste in Helix mode.

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 is consistent with the [UI/UX
checklist](<https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist>)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur when pasting at the end of a file in
Helix mode
```

## Parents

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

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