Skip to content

Commit

Permalink
Ensure hunk controls have unique element ids (#23815)
Browse files Browse the repository at this point in the history
This fixes an edge case when two hunk controls button groups were
visible (due to having text cursor on one hunk, and mouse cursor on the
other). In that situation, the mouse states for the two button groups
would mirror.

Release Notes:

- N/A
  • Loading branch information
maxbrunsfeld authored Jan 29, 2025
1 parent 33d1145 commit 442ea50
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3829,8 +3829,13 @@ impl EditorElement {
- scroll_pixel_position.y;
let x = text_hitbox.bounds.right() - px(100.);

let mut element =
diff_hunk_controls(multi_buffer_range.clone(), line_height, &editor, cx);
let mut element = diff_hunk_controls(
display_row_range.start.0,
multi_buffer_range.clone(),
line_height,
&editor,
cx,
);
element.prepaint_as_root(
gpui::Point::new(x, y),
size(px(100.0), line_height).into(),
Expand Down Expand Up @@ -8524,6 +8529,7 @@ mod tests {
}

fn diff_hunk_controls(
row: u32,
hunk_range: Range<Anchor>,
line_height: Pixels,
editor: &Entity<Editor>,
Expand All @@ -8541,7 +8547,7 @@ fn diff_hunk_controls(
.bg(cx.theme().colors().editor_background)
.gap_1()
.child(
IconButton::new("next-hunk", IconName::ArrowDown)
IconButton::new(("next-hunk", row as u64), IconName::ArrowDown)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
// .disabled(!has_multiple_hunks)
Expand All @@ -8564,7 +8570,7 @@ fn diff_hunk_controls(
}),
)
.child(
IconButton::new("prev-hunk", IconName::ArrowUp)
IconButton::new(("prev-hunk", row as u64), IconName::ArrowUp)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
// .disabled(!has_multiple_hunks)
Expand Down

0 comments on commit 442ea50

Please sign in to comment.