Fix bug where all editor completions would be black (#28548)

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-04-10 17:59:10 -06:00 committed by GitHub
parent fd256d159d
commit c0262cf62f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 10 deletions

View file

@ -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,

View file

@ -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<Pixels>,
line_height: Pixels,
text_style: Option<&TextStyle>,
text_style: Option<&TextStyleRefinement>,
bounds: Option<Bounds<Pixels>>,
window: &mut Window,
cx: &mut App,
@ -190,7 +190,7 @@ fn paint_line(
origin: Point<Pixels>,
layout: &LineLayout,
line_height: Pixels,
text_style: Option<&TextStyle>,
text_style: Option<&TextStyleRefinement>,
align_width: Option<Pixels>,
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()) {