From 13de400a2acc809bc4d69e38ee3a166d6d412614 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Thu, 4 Sep 2025 00:03:48 +0530 Subject: [PATCH] editor: Do not correct text contrast on non-opaque editor (#37471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don’t know the background color behind a non-opaque editor, so we should skip contrast correction in that case. This prevents single-editor mode (which is always transparent) from showing weird text colors when text is selected. We can’t account for the actual background during contrast correction because we compute contrast outside gpui, while the actual color blending happens inside gpui during drawing. image Release Notes: - Fixed an issue where Command Palette text looked faded when selected. --- crates/editor/src/element.rs | 8 ++++++-- crates/gpui/src/color.rs | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index fd5e544725696c63af2458447c66813f12f4cba3..c21d31aa5c14e3b596a6089630b29a3e55a3084d 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 cb7329c03fbb2064da0ef5873eef92c2c33d4953..93c69744a6f9f3cc74e7696e9edf49001587376b 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.