Skip to content

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

@notpeter

Description

@notpeter

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:

zed/crates/util/src/util.rs

Lines 129 to 132 in 8e12c67

items.select_nth_unstable_by(limit, compare);
items.truncate(limit);
items.sort_by(compare);
}

And the following buffer state:
Screenshot 2025-01-01 at 12 12 27

Copy Permalink gives me this link (line 132):


But this is what I expected (line 129):
items.select_nth_unstable_by(limit, compare);

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

Metadata

Metadata

Assignees

Labels

bite-sizesmall issueseditorFeedback for code editing, formatting, editor iterations, etcgitGit integration feedbackreproducibleVerified steps to reproduce included

Type

Projects

Status

Let's Git Together

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions