Skip to content

Commit bee6cbb

Browse files
maxbrunsfeldmaxdeviant
authored andcommitted
Fix detection that a diff hunk is expanded (zed-industries#18302)
Release Notes: - N/A --------- Co-authored-by: Marshall <marshall@zed.dev>
1 parent 4917e94 commit bee6cbb

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

crates/collab/src/tests/editor_tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,10 +2214,7 @@ struct Row10;"#};
22142214
let snapshot = editor.snapshot(cx);
22152215
let all_hunks = editor_hunks(editor, &snapshot, cx);
22162216
let all_expanded_hunks = expanded_hunks(editor, &snapshot, cx);
2217-
assert_eq!(
2218-
expanded_hunks_background_highlights(editor, cx),
2219-
vec![DisplayRow(5)..=DisplayRow(5)]
2220-
);
2217+
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
22212218
assert_eq!(
22222219
all_hunks,
22232220
vec![(

crates/editor/src/element.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,11 @@ impl EditorElement {
13351335
}
13361336
match status {
13371337
DiffHunkStatus::Added => {}
1338-
DiffHunkStatus::Modified => {}
1338+
DiffHunkStatus::Modified => {
1339+
if is_expanded {
1340+
*status = DiffHunkStatus::Added;
1341+
}
1342+
}
13391343
DiffHunkStatus::Removed => {
13401344
if is_expanded {
13411345
return None;

crates/editor/src/hunk_diff.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,12 @@ impl Editor {
279279
..Point::new(remaining_hunk.row_range.end.0, 0);
280280
hunks_to_expand.push(HoveredHunk {
281281
status: hunk_status(&remaining_hunk),
282-
multi_buffer_range: remaining_hunk_point_range
283-
.to_anchors(&snapshot.buffer_snapshot),
282+
multi_buffer_range: snapshot
283+
.buffer_snapshot
284+
.anchor_before(remaining_hunk_point_range.start)
285+
..snapshot
286+
.buffer_snapshot
287+
.anchor_after(remaining_hunk_point_range.end),
284288
diff_base_byte_range: remaining_hunk.diff_base_byte_range.clone(),
285289
});
286290
}

0 commit comments

Comments
 (0)