Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Fix panics that could occur when content mask had negative bounds (#47327)

Anthony Eid01d72aa7d6de
diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs
index fc735ba5e0e..6d9a4fe2815 100644
--- a/crates/gpui/src/geometry.rs
+++ b/crates/gpui/src/geometry.rs
@@ -1112,7 +1112,10 @@ impl<T: PartialOrd + Add<T, Output = T> + Sub<Output = T> + Clone + Debug + Defa
/// ```
pub fn intersect(&self, other: &Self) -> Self {
let upper_left = self.origin.max(&other.origin);
- let bottom_right = self.bottom_right().min(&other.bottom_right());
+ let bottom_right = self
+ .bottom_right()
+ .min(&other.bottom_right())
+ .max(&upper_left);
Self::from_corners(upper_left, bottom_right)
}
diff --git a/crates/gpui/src/style.rs b/crates/gpui/src/style.rs
index 7481b8001e5..d1ab41ff30a 100644
--- a/crates/gpui/src/style.rs
+++ b/crates/gpui/src/style.rs
@@ -666,23 +666,31 @@ impl Style {
let border_widths = self.border_widths.to_pixels(rem_size);
let max_border_width = border_widths.max();
let max_corner_radius = corner_radii.max();
+ let zero_size = Size {
+ width: Pixels::ZERO,
+ height: Pixels::ZERO,
+ };
- let top_bounds = Bounds::from_corners(
+ let mut top_bounds = Bounds::from_corners(
bounds.origin,
bounds.top_right() + point(Pixels::ZERO, max_border_width.max(max_corner_radius)),
);
- let bottom_bounds = Bounds::from_corners(
+ top_bounds.size = top_bounds.size.max(&zero_size);
+ let mut bottom_bounds = Bounds::from_corners(
bounds.bottom_left() - point(Pixels::ZERO, max_border_width.max(max_corner_radius)),
bounds.bottom_right(),
);
- let left_bounds = Bounds::from_corners(
+ bottom_bounds.size = bottom_bounds.size.max(&zero_size);
+ let mut left_bounds = Bounds::from_corners(
top_bounds.bottom_left(),
bottom_bounds.origin + point(max_border_width, Pixels::ZERO),
);
- let right_bounds = Bounds::from_corners(
+ left_bounds.size = left_bounds.size.max(&zero_size);
+ let mut right_bounds = Bounds::from_corners(
top_bounds.bottom_right() - point(max_border_width, Pixels::ZERO),
bottom_bounds.top_right(),
);
+ right_bounds.size = right_bounds.size.max(&zero_size);
let mut background = self.border_color.unwrap_or_default();
background.a = 0.;