Skip to content

Commit

Permalink
Fix duplicate hunk controls after splitting DisplayDiffHunk (zed-indu…
Browse files Browse the repository at this point in the history
…stries#24893)

This PR fixes expanded modification hunks having two sets of hunk
controls after zed-industries#24834.

Release Notes:

- N/A
  • Loading branch information
cole-miller authored Feb 14, 2025
1 parent 610158b commit de020af
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum DisplayDiffHunk {
multi_buffer_range: Range<Anchor>,
status: DiffHunkStatus,
expanded: bool,
is_primary: bool,
},
}

Expand Down Expand Up @@ -1605,6 +1606,7 @@ impl EditorElement {
hunk.buffer_range.clone(),
),
expanded,
is_primary: true,
},
None,
));
Expand All @@ -1620,6 +1622,7 @@ impl EditorElement {
hunk.buffer_range,
),
expanded,
is_primary: false,
},
None,
));
Expand All @@ -1644,6 +1647,7 @@ impl EditorElement {
hunk.buffer_range,
),
expanded,
is_primary: true,
},
None,
));
Expand Down Expand Up @@ -4205,14 +4209,29 @@ impl EditorElement {
newest_cursor_position,
];

for (hunk, _) in display_hunks {
let mut display_hunks = display_hunks.iter().peekable();
while let Some((hunk, _)) = display_hunks.next() {
if let DisplayDiffHunk::Unfolded {
display_row_range,
multi_buffer_range,
status,
is_primary: true,
..
} = &hunk
{
let mut display_row_range = display_row_range.clone();
if let Some((
DisplayDiffHunk::Unfolded {
display_row_range: secondary_display_row_range,
is_primary: false,
..
},
_,
)) = display_hunks.peek()
{
display_row_range.end = secondary_display_row_range.end;
}

if display_row_range.start < row_range.start
|| display_row_range.start >= row_range.end
{
Expand Down

0 comments on commit de020af

Please sign in to comment.