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
3284 if rows.start >= rows.end {3284 if rows.start >= rows.end {
3285 return Vec::new();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 let highlight_iter = highlight_ranges.iter().cloned();3291 let highlight_iter = highlight_ranges.iter().cloned();
3288 let selection_iter = selections.iter().flat_map(|(player_color, layouts)| {3292 let selection_iter = selections.iter().flat_map(|(player_color, layouts)| {
3289 let color = player_color.selection;3293 let color = player_color.selection;
@@ -11005,7 +11009,7 @@ mod tests { · 7715 unmodified lines
11005 11009
11006 #[gpui::test]11010 #[gpui::test]
11007 fn test_merge_overlapping_ranges() {11011 fn test_merge_overlapping_ranges() {
11008 let base_bg = Hsla::default();11012 let base_bg = Hsla::white();
11009 let color1 = Hsla {11013 let color1 = Hsla {
11010 h: 0.0,11014 h: 0.0,
11011 s: 0.5,11015 s: 0.5,
@@ -11075,7 +11079,7 @@ mod tests { · 63 unmodified lines
11075 11079
11076 #[gpui::test]11080 #[gpui::test]
11077 fn test_bg_segments_per_row() {11081 fn test_bg_segments_per_row() {
11078 let base_bg = Hsla::default();11082 let base_bg = Hsla::white();
11079 11083
11080 // Case A: selection spans three display rows: row 1 [5, end), full row 2, row 3 [0, 7)11084 // Case A: selection spans three display rows: row 1 [5, end), full row 2, row 3 [0, 7)
11081 {11085 {
crates/gpui/src/color.rs+5−0
@@ -473,6 +473,11 @@ impl Hsla { · 472 unmodified lines
473 self.a == 0.0473 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 /// 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.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 /// If `other`'s alpha value is 1.0 or greater, `other` color is fully opaque, thus `other` is returned as the output color.483 /// 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