From da1ef13442e095414e23db86623a5b5acd117cd3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 24 Sep 2024 14:39:44 -0700 Subject: [PATCH] Fix detection that a diff hunk is expanded (#18302) Release Notes: - N/A --------- Co-authored-by: Marshall --- crates/collab/src/tests/editor_tests.rs | 5 +---- crates/editor/src/element.rs | 6 +++++- crates/editor/src/hunk_diff.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index 7fb1a49f870d97ac0c8361348d38d618c2a1bbff..121c93656305a6401b648c371ba2aa2df7c98fdf 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -2214,10 +2214,7 @@ struct Row10;"#}; let snapshot = editor.snapshot(cx); let all_hunks = editor_hunks(editor, &snapshot, cx); let all_expanded_hunks = expanded_hunks(editor, &snapshot, cx); - assert_eq!( - expanded_hunks_background_highlights(editor, cx), - vec![DisplayRow(5)..=DisplayRow(5)] - ); + assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new()); assert_eq!( all_hunks, vec![( diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 3be71aeefba94228803ccf03bbddaccfab7ddcf7..31e4efb83b60e797b8525e23a61337d18b7f1204 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1335,7 +1335,11 @@ impl EditorElement { } match status { DiffHunkStatus::Added => {} - DiffHunkStatus::Modified => {} + DiffHunkStatus::Modified => { + if is_expanded { + *status = DiffHunkStatus::Added; + } + } DiffHunkStatus::Removed => { if is_expanded { return None; diff --git a/crates/editor/src/hunk_diff.rs b/crates/editor/src/hunk_diff.rs index 90836cee51683c4f76e09d06c104608cdeb6fec6..2f7bb49e85349194b70f568e07e17c8d99e7b836 100644 --- a/crates/editor/src/hunk_diff.rs +++ b/crates/editor/src/hunk_diff.rs @@ -279,8 +279,12 @@ impl Editor { ..Point::new(remaining_hunk.row_range.end.0, 0); hunks_to_expand.push(HoveredHunk { status: hunk_status(&remaining_hunk), - multi_buffer_range: remaining_hunk_point_range - .to_anchors(&snapshot.buffer_snapshot), + multi_buffer_range: snapshot + .buffer_snapshot + .anchor_before(remaining_hunk_point_range.start) + ..snapshot + .buffer_snapshot + .anchor_after(remaining_hunk_point_range.end), diff_base_byte_range: remaining_hunk.diff_base_byte_range.clone(), }); }