# Use buffer line numbers when copying file locations \(\#60781\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 1c5b2b815b5107fb4734a7286eed727ea4906e5c

Requested commit: 1c5b2b815b5107fb4734a7286eed727ea4906e5c

Commit: 1c5b2b815b5107fb4734a7286eed727ea4906e5c

Tree: dd2ecb62b09dfd110bae38a38134b3e6a34b95f1

Author: Apoorva Verma

Committer: GitHub

## Message

```
Use buffer line numbers when copying file locations (#60781)

# Objective

Fixes #54250

`editor: copy file location` copies the row you're on in the
multi-buffer, not the row in the actual file. In a git diff view with
collapsed lines it copies the wrong line number.

## Solution

It read the rows straight off the selection, which is in multi-buffer
coordinates. `ClipboardSelection::for_buffer` already handles this with
`range_to_buffer_range`, so I used the same thing. Path and line now
come from the same buffer.

`range_to_buffer_range` returns nothing when the selection ends in a
different buffer than it starts in, which you can do in a git diff view.
Rather than copy nothing, it falls back to the cursor's buffer.

## Testing

Three tests: a multi-buffer excerpt, a selection dragged across two
files, and a plain single-file editor. The multi-buffer ones fail on
main; the singleton one passes either way, so normal editors are
unaffected.

## 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 `editor: copy file location` copying the wrong line number in
multibuffers
([#54250](https://github.com/zed-industries/zed/issues/54250)).

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
```

## Parents

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

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