Fix inline blame annotations handling wrapped lines (#10600)

Fixes inline blame not being displayed correctly for soft-wrapped lines.

(Can't find the ticket)
![screenshot-2024-04-16-10 50
29](https://github.com/zed-industries/zed/assets/1185253/e3ff9018-f796-469a-9d42-5997baf7d2f6)


Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-04-16 11:27:23 +02:00 committed by GitHub
parent 2cfb1ffa77
commit 08aef198d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1099,9 +1099,9 @@ impl EditorElement {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn layout_inline_blame( fn layout_inline_blame(
&self, &self,
start_row: u32, display_row: u32,
row: u32, display_snapshot: &DisplaySnapshot,
line_layouts: &[LineWithInvisibles], line_layout: &LineWithInvisibles,
em_width: Pixels, em_width: Pixels,
content_origin: gpui::Point<Pixels>, content_origin: gpui::Point<Pixels>,
scroll_pixel_position: gpui::Point<Pixels>, scroll_pixel_position: gpui::Point<Pixels>,
@ -1115,29 +1115,33 @@ impl EditorElement {
return None; return None;
} }
let blame = self.editor.read(cx).blame.clone()?;
let workspace = self let workspace = self
.editor .editor
.read(cx) .read(cx)
.workspace .workspace
.as_ref() .as_ref()
.map(|(w, _)| w.clone()); .map(|(w, _)| w.clone());
let display_point = DisplayPoint::new(display_row, 0);
let buffer_row = display_point.to_point(display_snapshot).row;
let blame = self.editor.read(cx).blame.clone()?;
let blame_entry = blame let blame_entry = blame
.update(cx, |blame, cx| blame.blame_for_rows([Some(row)], cx).next()) .update(cx, |blame, cx| {
blame.blame_for_rows([Some(buffer_row)], cx).next()
})
.flatten()?; .flatten()?;
let mut element = let mut element =
render_inline_blame_entry(&blame, blame_entry, &self.style, workspace, cx); render_inline_blame_entry(&blame, blame_entry, &self.style, workspace, cx);
let start_y = let start_y = content_origin.y
content_origin.y + line_height * (row as f32 - scroll_pixel_position.y / line_height); + line_height * (display_row as f32 - scroll_pixel_position.y / line_height);
let start_x = { let start_x = {
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.; const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.;
let line_layout = &line_layouts[(row - start_row) as usize];
let line_width = line_layout.line.width; let line_width = line_layout.line.width;
content_origin.x + line_width + (em_width * INLINE_BLAME_PADDING_EM_WIDTHS) content_origin.x + line_width + (em_width * INLINE_BLAME_PADDING_EM_WIDTHS)
}; };
@ -3697,11 +3701,13 @@ impl Element for EditorElement {
let mut inline_blame = None; let mut inline_blame = None;
if let Some(newest_selection_head) = newest_selection_head { if let Some(newest_selection_head) = newest_selection_head {
if (start_row..end_row).contains(&newest_selection_head.row()) { let display_row = newest_selection_head.row();
if (start_row..end_row).contains(&display_row) {
let line_layout = &line_layouts[(display_row - start_row) as usize];
inline_blame = self.layout_inline_blame( inline_blame = self.layout_inline_blame(
start_row, display_row,
newest_selection_head.row(), &snapshot.display_snapshot,
&line_layouts, line_layout,
em_width, em_width,
content_origin, content_origin,
scroll_pixel_position, scroll_pixel_position,