From c0262cf62f6d1443e22012abef2131cafcaa4b29 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 10 Apr 2025 17:59:10 -0600 Subject: [PATCH] Fix bug where all editor completions would be black (#28548) Release Notes: - N/A --- crates/gpui/src/elements/text.rs | 14 ++++++++++---- crates/gpui/src/text_system/line.rs | 14 ++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index c264e3c6b7b3e90151efa6dc79caa4a23f16536f..faacbc75527fd26f572c772b2a85a87f6406d0c7 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -1,10 +1,12 @@ use crate::{ ActiveTooltip, AnyView, App, Bounds, DispatchPhase, Element, ElementId, GlobalElementId, HighlightStyle, Hitbox, IntoElement, LayoutId, MouseDownEvent, MouseMoveEvent, MouseUpEvent, - Pixels, Point, SharedString, Size, TextOverflow, TextRun, TextStyle, TooltipId, WhiteSpace, - Window, WrappedLine, WrappedLineLayout, register_tooltip_mouse_handlers, set_tooltip_on_window, + Pixels, Point, SharedString, Size, TextAlign, TextOverflow, TextRun, TextStyle, + TextStyleRefinement, TooltipId, WhiteSpace, Window, WrappedLine, WrappedLineLayout, + register_tooltip_mouse_handlers, set_tooltip_on_window, }; use anyhow::anyhow; +use refineable::Refineable as _; use smallvec::SmallVec; use std::{ cell::{Cell, RefCell}, @@ -416,13 +418,17 @@ impl TextLayout { let line_height = element_state.line_height; let mut line_origin = bounds.origin; - let text_style = window.text_style(); + // Get current text_style refinements + let mut text_style = TextStyleRefinement::default(); + for style in window.text_style_stack.iter().as_ref() { + text_style.refine(&style); + } for line in &element_state.lines { line.paint_background( line_origin, line_height, - text_style.text_align, + text_style.text_align.unwrap_or(TextAlign::Left), Some(bounds), window, cx, diff --git a/crates/gpui/src/text_system/line.rs b/crates/gpui/src/text_system/line.rs index f7553abcea3f488757f57d5ab1ceb0b648361153..35037b261c3d17a25974661a31d956a33d7a73b4 100644 --- a/crates/gpui/src/text_system/line.rs +++ b/crates/gpui/src/text_system/line.rs @@ -1,7 +1,7 @@ use crate::{ App, Bounds, Half, Hsla, LineLayout, Pixels, Point, Result, SharedString, StrikethroughStyle, - TextAlign, TextStyle, UnderlineStyle, Window, WrapBoundary, WrappedLineLayout, black, fill, - point, px, size, + TextAlign, TextStyleRefinement, UnderlineStyle, Window, WrapBoundary, WrappedLineLayout, black, + fill, point, px, size, }; use derive_more::{Deref, DerefMut}; use smallvec::SmallVec; @@ -130,7 +130,7 @@ impl WrappedLine { &self, origin: Point, line_height: Pixels, - text_style: Option<&TextStyle>, + text_style: Option<&TextStyleRefinement>, bounds: Option>, window: &mut Window, cx: &mut App, @@ -190,7 +190,7 @@ fn paint_line( origin: Point, layout: &LineLayout, line_height: Pixels, - text_style: Option<&TextStyle>, + text_style: Option<&TextStyleRefinement>, align_width: Option, decoration_runs: &[DecorationRun], wrap_boundaries: &[WrapBoundary], @@ -206,7 +206,9 @@ fn paint_line( ); // TODO: text_align and line_height need to inherit from normal style when is hovered or activated. - let mut text_align = text_style.map(|s| s.text_align).unwrap_or(TextAlign::Left); + let mut text_align = text_style + .and_then(|s| s.text_align) + .unwrap_or(TextAlign::Left); window.paint_layer(line_bounds, |window| { let padding_top = (line_height - layout.ascent - layout.descent) / 2.; @@ -301,7 +303,7 @@ fn paint_line( let mut run_underline = style_run.underline.as_ref(); let mut run_strikethrough = style_run.strikethrough; // Override by text run by current style when hovered or activated. - if let Some(val) = text_style.map(|s| s.color) { + if let Some(val) = text_style.and_then(|s| s.color) { run_color = val; } if let Some(val) = text_style.and_then(|s| s.underline.as_ref()) {