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.

Fix incorrect ANSI color contrast adjustment on some background colors (#38155)

Tim Vermeulen5b1c87b6a600
diff --git a/crates/gpui/src/color.rs b/crates/gpui/src/color.rs
index c6c4cdc77b1..b84f8699e38 100644
--- a/crates/gpui/src/color.rs
+++ b/crates/gpui/src/color.rs
@@ -151,9 +151,9 @@ impl From<Hsla> for Rgba {
};
Rgba {
- r,
- g,
- b,
+ r: r.clamp(0., 1.),
+ g: g.clamp(0., 1.),
+ b: b.clamp(0., 1.),
a: color.a,
}
}
diff --git a/crates/ui/src/utils/apca_contrast.rs b/crates/ui/src/utils/apca_contrast.rs
index 522dca3e913..341b44670d8 100644
--- a/crates/ui/src/utils/apca_contrast.rs
+++ b/crates/ui/src/utils/apca_contrast.rs
@@ -393,6 +393,13 @@ mod tests {
);
}
+ #[test]
+ fn test_srgb_to_y_nan_issue() {
+ let dark_red = hsla_from_hex(0x5f0000);
+ let y_dark_red = srgb_to_y(dark_red, &APCAConstants::default());
+ assert!(!y_dark_red.is_nan());
+ }
+
#[test]
fn test_ensure_minimum_contrast() {
let white_bg = hsla(0.0, 0.0, 1.0, 1.0);