History

editor: Do not correct text contrast on non-opaque editor (#37471)

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.

Smit Barmase committed 1 year ago

Commit 13de4001 parent c3480c32 files · +11 −2Browse files

Unified · Split

2 files
  1. crates/editor/src/element.rs +6 −2
  2. crates/gpui/src/color.rs +5 −0
crates/editor/src/element.rs+6−2
@@ -3284,6 +3284,10 @@ impl EditorElement { · 3283 unmodified lines
32843284 if rows.start >= rows.end {
32853285 return Vec::new();
32863286 }
3287+ if !base_background.is_opaque() {
3288+ // We don't actually know what color is behind this editor.
3289+ return Vec::new();
3290+ }
32873291 let highlight_iter = highlight_ranges.iter().cloned();
32883292 let selection_iter = selections.iter().flat_map(|(player_color, layouts)| {
32893293 let color = player_color.selection;
@@ -11005,7 +11009,7 @@ mod tests { · 7715 unmodified lines
1100511009
1100611010 #[gpui::test]
1100711011 fn test_merge_overlapping_ranges() {
11008− let base_bg = Hsla::default();
11012+ let base_bg = Hsla::white();
1100911013 let color1 = Hsla {
1101011014 h: 0.0,
1101111015 s: 0.5,
@@ -11075,7 +11079,7 @@ mod tests { · 63 unmodified lines
1107511079
1107611080 #[gpui::test]
1107711081 fn test_bg_segments_per_row() {
11078− let base_bg = Hsla::default();
11082+ let base_bg = Hsla::white();
1107911083
1108011084 // Case A: selection spans three display rows: row 1 [5, end), full row 2, row 3 [0, 7)
1108111085 {
crates/gpui/src/color.rs+5−0
@@ -473,6 +473,11 @@ impl Hsla { · 472 unmodified lines
473473 self.a == 0.0
474474 }
475475
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+
476481 /// 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.
477482 ///
478483 /// If `other`'s alpha value is 1.0 or greater, `other` color is fully opaque, thus `other` is returned as the output color.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t