git: Make permalinks aware of current diffs (#41915)
Addressing #22546, we want git permalinks to be aware of the current changes within the buffer. This change calculates how many lines have been added/deleted between the start and end of the selection and uses those values to offset the selection. This is done within `Editor::get_permalink_to_line` so that it can be passed to any git_store. Example: <img width="284" height="316" alt="image" src="https://github.com/user-attachments/assets/268043a0-2fc8-41c1-b094-d650fd4e0ae0" /> Where this selections permalink would previously return L3-L9, it now returns L2-L7. Release Notes: - git: make permalinks aware of current diffs Closes #22546 --- This is my first PR into the zed repository so very happy for any feedback on how I've implemented this. Thanks!
This commit is contained in:
@@ -20973,9 +20973,22 @@ impl Editor {
|
||||
buffer_ranges.last()
|
||||
}?;
|
||||
|
||||
let selection = text::ToPoint::to_point(&range.start, buffer).row
|
||||
..text::ToPoint::to_point(&range.end, buffer).row;
|
||||
Some((multi_buffer.buffer(buffer.remote_id()).unwrap(), selection))
|
||||
let start_row_in_buffer = text::ToPoint::to_point(&range.start, buffer).row;
|
||||
let end_row_in_buffer = text::ToPoint::to_point(&range.end, buffer).row;
|
||||
|
||||
let Some(buffer_diff) = multi_buffer.diff_for(buffer.remote_id()) else {
|
||||
let selection = start_row_in_buffer..end_row_in_buffer;
|
||||
|
||||
return Some((multi_buffer.buffer(buffer.remote_id()).unwrap(), selection));
|
||||
};
|
||||
|
||||
let buffer_diff_snapshot = buffer_diff.read(cx).snapshot(cx);
|
||||
|
||||
Some((
|
||||
multi_buffer.buffer(buffer.remote_id()).unwrap(),
|
||||
buffer_diff_snapshot.row_to_base_text_row(start_row_in_buffer, buffer)
|
||||
..buffer_diff_snapshot.row_to_base_text_row(end_row_in_buffer, buffer),
|
||||
))
|
||||
});
|
||||
|
||||
let Some((buffer, selection)) = buffer_and_selection else {
|
||||
|
||||
Reference in New Issue
Block a user