Copy Permalink (GitHub, etc) should better handle modified code
Summary
Copy Permalink does not work correctly on modified files (links to wrong line)
Steps to reproduce:
- Edit a file in a git repo add a bunch of comment to an existing file
- Right click and select
Copy Permalinkto a line later in the file.
Notice that the linked line number is offset from the code you were trying to link.
For example, given the following committed code:
https://github.com/zed-industries/zed/blob/8e12c679fc5a6c4ff6389c7a6a98a9878e350e36/crates/util/src/util.rs#L129-L132
And the following buffer state:
Copy Permalink gives me this link (line 132): https://github.com/zed-industries/zed/blob/8e12c679fc5a6c4ff6389c7a6a98a9878e350e36/crates/util/src/util.rs#L132 But this is what I expected (line 129): https://github.com/zed-industries/zed/blob/8e12c679fc5a6c4ff6389c7a6a98a9878e350e36/crates/util/src/util.rs#L129
I'm not positive the best behavior, but I think Zed can do better:
- For unchanged/pre-existing lines: line number should be to the line number of that code in the commit.
- For selections/lines which start or end on a newly inserted line (not present in the commit) Zed could expand the selection up/down so that's it's anchored to lines which actually exist in the commit.
Zed Version and System Specs
Zed: v0.167.1 (Zed Preview) OS: macOS 14.7.0 Memory: 64 GiB Architecture: aarch64
This is technically fixable now we have the diff hunks available to the editor....
I'd like to tackle this one, I can reproduce this issue and see a solution using the MultiBufferDiffHunk struct 🙂