zed icon indicating copy to clipboard operation
zed copied to clipboard

Copy Permalink (GitHub, etc) should better handle modified code

Open notpeter opened this issue 11 months ago • 1 comments

Summary

Copy Permalink does not work correctly on modified files (links to wrong line)

Steps to reproduce:

  1. Edit a file in a git repo add a bunch of comment to an existing file
  2. Right click and select Copy Permalink to 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: Screenshot 2025-01-01 at 12 12 27

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

notpeter avatar Jan 01 '25 17:01 notpeter

This is technically fixable now we have the diff hunks available to the editor....

ConradIrwin avatar Jan 30 '25 18:01 ConradIrwin

I'd like to tackle this one, I can reproduce this issue and see a solution using the MultiBufferDiffHunk struct 🙂

siame avatar Nov 02 '25 22:11 siame