From cda78c12ab88fb6f77bc9b16f7ded61d7a004461 Mon Sep 17 00:00:00 2001 From: Siame Rafiq Date: Thu, 11 Dec 2025 15:53:20 +0000 Subject: [PATCH] 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: image 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! --- crates/editor/src/editor.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 30e040fac1fc5682cbae8f9261c6996ec48a074d..c20b928df927a9ce764fe622e1d7f69c8de0c29f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -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 {