diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 21ad1aacbe..dc62b2e923 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -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); diff --git a/crates/editor/src/git.rs b/crates/editor/src/git.rs index 6f79580399..549d74a0b5 100644 --- a/crates/editor/src/git.rs +++ b/crates/editor/src/git.rs @@ -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, + display_row_range: RangeInclusive, 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, 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, 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(), } } diff --git a/crates/git/src/diff.rs b/crates/git/src/diff.rs index bdcb796e5b..e808eee24f 100644 --- a/crates/git/src/diff.rs +++ b/crates/git/src/diff.rs @@ -177,7 +177,7 @@ impl BufferDiff { let mut first_deletion_buffer_row: Option = None; let mut buffer_row_range: Option> = None; - let mut head_byte_range: Option> = None; + let mut diff_base_byte_range: Option> = 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, } } }