Layout git gutters inclusively

This commit is contained in:
Julia 2022-10-31 14:35:42 -04:00
parent c8fbc0d348
commit 7ac45379eb
3 changed files with 22 additions and 21 deletions

View file

@ -605,7 +605,7 @@ impl EditorElement {
//TODO: This rendering is entirely a horrible hack
DiffHunkStatus::Removed => {
let row = display_row_range.start;
let row = *display_row_range.start();
let offset = line_height / 2.;
let start_y = row as f32 * line_height - offset - scroll_top;
@ -627,11 +627,11 @@ impl EditorElement {
}
};
let start_row = display_row_range.start;
let end_row = display_row_range.end;
let start_row = *display_row_range.start();
let end_row = *display_row_range.end();
let start_y = start_row as f32 * line_height - scroll_top;
let end_y = end_row as f32 * line_height - scroll_top;
let end_y = end_row as f32 * line_height - scroll_top + line_height;
let width = diff_style.width_em * line_height;
let highlight_origin = bounds.origin() + vec2f(-width, start_y);

View file

@ -1,4 +1,4 @@
use std::ops::Range;
use std::ops::RangeInclusive;
use git::diff::{DiffHunk, DiffHunkStatus};
use language::Point;
@ -15,7 +15,7 @@ pub enum DisplayDiffHunk {
},
Unfolded {
display_row_range: Range<u32>,
display_row_range: RangeInclusive<u32>,
status: DiffHunkStatus,
},
}
@ -26,7 +26,7 @@ impl DisplayDiffHunk {
&DisplayDiffHunk::Folded { display_row } => display_row,
DisplayDiffHunk::Unfolded {
display_row_range, ..
} => display_row_range.start,
} => *display_row_range.start(),
}
}
@ -36,13 +36,7 @@ impl DisplayDiffHunk {
DisplayDiffHunk::Unfolded {
display_row_range, ..
} => {
if display_row_range.len() == 0 {
display_row_range.start..=display_row_range.end
} else {
display_row_range.start..=display_row_range.end - 1
}
}
} => display_row_range.clone(),
};
range.contains(&display_row)
@ -51,7 +45,6 @@ impl DisplayDiffHunk {
pub fn diff_hunk_to_display(hunk: DiffHunk<u32>, snapshot: &DisplaySnapshot) -> DisplayDiffHunk {
let hunk_start_point = Point::new(hunk.buffer_range.start, 0);
let hunk_end_point = Point::new(hunk.buffer_range.end, 0);
let hunk_start_point_sub = Point::new(hunk.buffer_range.start.saturating_sub(1), 0);
let hunk_end_point_sub = Point::new(
hunk.buffer_range
@ -83,9 +76,17 @@ pub fn diff_hunk_to_display(hunk: DiffHunk<u32>, snapshot: &DisplaySnapshot) ->
DisplayDiffHunk::Folded { display_row: row }
} else {
let start = hunk_start_point.to_display_point(snapshot).row();
let hunk_end_row_inclusive = hunk
.buffer_range
.end
.saturating_sub(1)
.max(hunk.buffer_range.start);
let hunk_end_point = Point::new(hunk_end_row_inclusive, 0);
let end = hunk_end_point.to_display_point(snapshot).row();
DisplayDiffHunk::Unfolded {
display_row_range: start..end,
display_row_range: start..=end,
status: hunk.status(),
}
}

View file

@ -177,7 +177,7 @@ impl BufferDiff {
let mut first_deletion_buffer_row: Option<u32> = None;
let mut buffer_row_range: Option<Range<u32>> = None;
let mut head_byte_range: Option<Range<usize>> = None;
let mut diff_base_byte_range: Option<Range<usize>> = None;
for line_index in 0..line_item_count {
let line = patch.line_in_hunk(hunk_index, line_index).unwrap();
@ -198,9 +198,9 @@ impl BufferDiff {
if kind == GitDiffLineType::Deletion {
let end = content_offset + content_len;
match &mut head_byte_range {
match &mut diff_base_byte_range {
Some(head_byte_range) => head_byte_range.end = end as usize,
None => head_byte_range = Some(content_offset as usize..end as usize),
None => diff_base_byte_range = Some(content_offset as usize..end as usize),
}
if first_deletion_buffer_row.is_none() {
@ -221,14 +221,14 @@ impl BufferDiff {
});
//unwrap_or addition without deletion
let head_byte_range = head_byte_range.unwrap_or(0..0);
let diff_base_byte_range = diff_base_byte_range.unwrap_or(0..0);
let start = Point::new(buffer_row_range.start, 0);
let end = Point::new(buffer_row_range.end, 0);
let buffer_range = buffer.anchor_before(start)..buffer.anchor_before(end);
DiffHunk {
buffer_range,
diff_base_byte_range: head_byte_range,
diff_base_byte_range,
}
}
}