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. <img width="522" height="145" alt="image" src="https://github.com/user-attachments/assets/6ee71475-f666-482d-87e6-15cf4c4fceef" /> Release Notes: - Fixed an issue where Command Palette text looked faded when selected.
Unified · Split
| @@ -3284,6 +3284,10 @@ impl EditorElement { · 3283 unmodified lines | ||
| 3284 | 3284 | if rows.start >= rows.end { |
| 3285 | 3285 | return Vec::new(); |
| 3286 | 3286 | } |
| 3287 | + if !base_background.is_opaque() { | |
| 3288 | + // We don't actually know what color is behind this editor. | |
| 3289 | + return Vec::new(); | |
| 3290 | + } | |
| 3287 | 3291 | let highlight_iter = highlight_ranges.iter().cloned(); |
| 3288 | 3292 | let selection_iter = selections.iter().flat_map(|(player_color, layouts)| { |
| 3289 | 3293 | let color = player_color.selection; |
| @@ -11005,7 +11009,7 @@ mod tests { · 7715 unmodified lines | ||
| 11005 | 11009 | |
| 11006 | 11010 | #[gpui::test] |
| 11007 | 11011 | fn test_merge_overlapping_ranges() { |
| 11008 | − let base_bg = Hsla::default(); | |
| 11012 | + let base_bg = Hsla::white(); | |
| 11009 | 11013 | let color1 = Hsla { |
| 11010 | 11014 | h: 0.0, |
| 11011 | 11015 | s: 0.5, |
| @@ -11075,7 +11079,7 @@ mod tests { · 63 unmodified lines | ||
| 11075 | 11079 | |
| 11076 | 11080 | #[gpui::test] |
| 11077 | 11081 | fn test_bg_segments_per_row() { |
| 11078 | − let base_bg = Hsla::default(); | |
| 11082 | + let base_bg = Hsla::white(); | |
| 11079 | 11083 | |
| 11080 | 11084 | // Case A: selection spans three display rows: row 1 [5, end), full row 2, row 3 [0, 7) |
| 11081 | 11085 | { |
| @@ -473,6 +473,11 @@ impl Hsla { · 472 unmodified lines | ||
| 473 | 473 | self.a == 0.0 |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | + /// Returns true if the HSLA color is fully opaque, false otherwise. | |
| 477 | + pub fn is_opaque(&self) -> bool { | |
| 478 | + self.a == 1.0 | |
| 479 | + } | |
| 480 | + | |
| 476 | 481 | /// 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. |
| 477 | 482 | /// |
| 478 | 483 | /// If `other`'s alpha value is 1.0 or greater, `other` color is fully opaque, thus `other` is returned as the output color. |