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: Do not correct text contrast on non-opaque editor (#37471)

Smit Barmase13de400a2acc
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index fd5e5447256..c21d31aa5c1 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -3284,6 +3284,10 @@ impl EditorElement {
if rows.start >= rows.end {
return Vec::new();
}
+ if !base_background.is_opaque() {
+ // We don't actually know what color is behind this editor.
+ return Vec::new();
+ }
let highlight_iter = highlight_ranges.iter().cloned();
let selection_iter = selections.iter().flat_map(|(player_color, layouts)| {
let color = player_color.selection;
@@ -11005,7 +11009,7 @@ mod tests {
#[gpui::test]
fn test_merge_overlapping_ranges() {
- let base_bg = Hsla::default();
+ let base_bg = Hsla::white();
let color1 = Hsla {
h: 0.0,
s: 0.5,
@@ -11075,7 +11079,7 @@ mod tests {
#[gpui::test]
fn test_bg_segments_per_row() {
- let base_bg = Hsla::default();
+ let base_bg = Hsla::white();
// Case A: selection spans three display rows: row 1 [5, end), full row 2, row 3 [0, 7)
{
diff --git a/crates/gpui/src/color.rs b/crates/gpui/src/color.rs
index cb7329c03fb..93c69744a6f 100644
--- a/crates/gpui/src/color.rs
+++ b/crates/gpui/src/color.rs
@@ -473,6 +473,11 @@ impl Hsla {
self.a == 0.0
}
+ /// Returns true if the HSLA color is fully opaque, false otherwise.
+ pub fn is_opaque(&self) -> bool {
+ self.a == 1.0
+ }
+
/// Blends `other` on top of `self` based on `other`'s alpha value. The resulting color is a combination of `self`'s and `other`'s colors.
///
/// If `other`'s alpha value is 1.0 or greater, `other` color is fully opaque, thus `other` is returned as the output color.