Merge pull request #2482 from zed-industries/add-hunks-to-scrollbar

Add diff hunks to the scroll bar
This commit is contained in:
Mikayla Maki 2023-05-17 11:51:01 -07:00 committed by GitHub
commit 1c9a7a7ad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1022,15 +1022,16 @@ impl EditorElement {
let mut first_row_y_offset = 0.0;
// Impose a minimum height on the scrollbar thumb
let row_height = height / max_row;
let min_thumb_height =
style.min_height_factor * cx.font_cache.line_height(self.style.text.font_size);
let thumb_height = (row_range.end - row_range.start) * height / max_row;
let thumb_height = (row_range.end - row_range.start) * row_height;
if thumb_height < min_thumb_height {
first_row_y_offset = (min_thumb_height - thumb_height) / 2.0;
height -= min_thumb_height - thumb_height;
}
let y_for_row = |row: f32| -> f32 { top + first_row_y_offset + row * height / max_row };
let y_for_row = |row: f32| -> f32 { top + first_row_y_offset + row * row_height };
let thumb_top = y_for_row(row_range.start) - first_row_y_offset;
let thumb_bottom = y_for_row(row_range.end) + first_row_y_offset;
@ -1044,6 +1045,50 @@ impl EditorElement {
background: style.track.background_color,
..Default::default()
});
let diff_style = cx.global::<Settings>().theme.editor.diff.clone();
for hunk in layout
.position_map
.snapshot
.buffer_snapshot
.git_diff_hunks_in_range(0..(max_row.floor() as u32), false)
{
let start_y = y_for_row(hunk.buffer_range.start as f32);
let mut end_y = if hunk.buffer_range.start == hunk.buffer_range.end {
y_for_row((hunk.buffer_range.end + 1) as f32)
} else {
y_for_row((hunk.buffer_range.end) as f32)
};
if end_y - start_y < 1. {
end_y = start_y + 1.;
}
let bounds = RectF::from_points(vec2f(left, start_y), vec2f(right, end_y));
let color = match hunk.status() {
DiffHunkStatus::Added => diff_style.inserted,
DiffHunkStatus::Modified => diff_style.modified,
DiffHunkStatus::Removed => diff_style.deleted,
};
let border = Border {
width: 1.,
color: style.thumb.border.color,
overlay: false,
top: false,
right: true,
bottom: false,
left: true,
};
scene.push_quad(Quad {
bounds,
background: Some(color),
border,
corner_radius: style.thumb.corner_radius,
})
}
scene.push_quad(Quad {
bounds: thumb_bounds,
border: style.thumb.border,