Revert buggy pr (#28554)

Earlier, I merged #24723

Before merging it, I made a change that was incorrect and fast followed
with a fix: #28548

Following that fix, @bennetbo discovered that the modals where no longer
highlighting correctly, particularly the outline modal.

So I'm going to revert it all.

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-04-10 18:58:36 -06:00 committed by GitHub
parent 71c2a11bd9
commit c143846e42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 70 deletions

View file

@ -8,13 +8,11 @@ struct HelloWorld {}
impl Render for HelloWorld { impl Render for HelloWorld {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div() div()
.font_family(".SystemUIFont")
.bg(gpui::white()) .bg(gpui::white())
.flex() .flex()
.flex_col() .flex_col()
.gap_2() .gap_2()
.p_4() .p_4()
.gap_4()
.size_full() .size_full()
.child(div().child("Text left")) .child(div().child("Text left"))
.child(div().text_center().child("Text center")) .child(div().text_center().child("Text center"))
@ -73,24 +71,6 @@ impl Render for HelloWorld {
.child("100%"), .child("100%"),
), ),
) )
.child(
div()
.id("Text Link")
.text_color(gpui::blue())
.cursor_pointer()
.active(|this| {
this.text_color(gpui::white())
.bg(gpui::blue())
.text_decoration_1()
.text_decoration_wavy()
})
.hover(|this| {
this.text_color(gpui::rgb(0x973717))
.bg(gpui::yellow())
.text_decoration_1()
})
.child("Text with hover, active styles"),
)
} }
} }

View file

@ -1666,7 +1666,7 @@ impl Interactivity {
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) { ) {
use crate::BorderStyle; use crate::{BorderStyle, TextAlign};
if global_id.is_some() if global_id.is_some()
&& (style.debug || style.debug_below || cx.has_global::<crate::DebugBelow>()) && (style.debug || style.debug_below || cx.has_global::<crate::DebugBelow>())
@ -1689,7 +1689,7 @@ impl Interactivity {
.ok() .ok()
.and_then(|mut text| text.pop()) .and_then(|mut text| text.pop())
{ {
text.paint(hitbox.origin, FONT_SIZE, None, None, window, cx) text.paint(hitbox.origin, FONT_SIZE, TextAlign::Left, None, window, cx)
.ok(); .ok();
let text_bounds = crate::Bounds { let text_bounds = crate::Bounds {

View file

@ -1,12 +1,10 @@
use crate::{ use crate::{
ActiveTooltip, AnyView, App, Bounds, DispatchPhase, Element, ElementId, GlobalElementId, ActiveTooltip, AnyView, App, Bounds, DispatchPhase, Element, ElementId, GlobalElementId,
HighlightStyle, Hitbox, IntoElement, LayoutId, MouseDownEvent, MouseMoveEvent, MouseUpEvent, HighlightStyle, Hitbox, IntoElement, LayoutId, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
Pixels, Point, SharedString, Size, TextAlign, TextOverflow, TextRun, TextStyle, Pixels, Point, SharedString, Size, TextOverflow, TextRun, TextStyle, TooltipId, WhiteSpace,
TextStyleRefinement, TooltipId, WhiteSpace, Window, WrappedLine, WrappedLineLayout, Window, WrappedLine, WrappedLineLayout, register_tooltip_mouse_handlers, set_tooltip_on_window,
register_tooltip_mouse_handlers, set_tooltip_on_window,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use refineable::Refineable as _;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{ use std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
@ -417,18 +415,12 @@ impl TextLayout {
let line_height = element_state.line_height; let line_height = element_state.line_height;
let mut line_origin = bounds.origin; 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 { for line in &element_state.lines {
line.paint_background( line.paint_background(
line_origin, line_origin,
line_height, line_height,
text_style.text_align.unwrap_or(TextAlign::Left), text_style.text_align,
Some(bounds), Some(bounds),
window, window,
cx, cx,
@ -437,7 +429,7 @@ impl TextLayout {
line.paint( line.paint(
line_origin, line_origin,
line_height, line_height,
Some(&text_style), text_style.text_align,
Some(bounds), Some(bounds),
window, window,
cx, cx,

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
App, Bounds, Half, Hsla, LineLayout, Pixels, Point, Result, SharedString, StrikethroughStyle, App, Bounds, Half, Hsla, LineLayout, Pixels, Point, Result, SharedString, StrikethroughStyle,
TextAlign, TextStyleRefinement, UnderlineStyle, Window, WrapBoundary, WrappedLineLayout, black, TextAlign, UnderlineStyle, Window, WrapBoundary, WrappedLineLayout, black, fill, point, px,
fill, point, px, size, size,
}; };
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -71,7 +71,7 @@ impl ShapedLine {
origin, origin,
&self.layout, &self.layout,
line_height, line_height,
None, TextAlign::default(),
None, None,
&self.decoration_runs, &self.decoration_runs,
&[], &[],
@ -125,12 +125,11 @@ impl WrappedLine {
} }
/// Paint this line of text to the window. /// Paint this line of text to the window.
#[allow(clippy::too_many_arguments)]
pub fn paint( pub fn paint(
&self, &self,
origin: Point<Pixels>, origin: Point<Pixels>,
line_height: Pixels, line_height: Pixels,
text_style: Option<&TextStyleRefinement>, align: TextAlign,
bounds: Option<Bounds<Pixels>>, bounds: Option<Bounds<Pixels>>,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
@ -144,7 +143,7 @@ impl WrappedLine {
origin, origin,
&self.layout.unwrapped_layout, &self.layout.unwrapped_layout,
line_height, line_height,
text_style, align,
align_width, align_width,
&self.decoration_runs, &self.decoration_runs,
&self.wrap_boundaries, &self.wrap_boundaries,
@ -190,7 +189,7 @@ fn paint_line(
origin: Point<Pixels>, origin: Point<Pixels>,
layout: &LineLayout, layout: &LineLayout,
line_height: Pixels, line_height: Pixels,
text_style: Option<&TextStyleRefinement>, align: TextAlign,
align_width: Option<Pixels>, align_width: Option<Pixels>,
decoration_runs: &[DecorationRun], decoration_runs: &[DecorationRun],
wrap_boundaries: &[WrapBoundary], wrap_boundaries: &[WrapBoundary],
@ -204,12 +203,6 @@ fn paint_line(
line_height * (wrap_boundaries.len() as f32 + 1.), line_height * (wrap_boundaries.len() as f32 + 1.),
), ),
); );
// TODO: text_align and line_height need to inherit from normal style when is hovered or activated.
let mut text_align = text_style
.and_then(|s| s.text_align)
.unwrap_or(TextAlign::Left);
window.paint_layer(line_bounds, |window| { window.paint_layer(line_bounds, |window| {
let padding_top = (line_height - layout.ascent - layout.descent) / 2.; let padding_top = (line_height - layout.ascent - layout.descent) / 2.;
let baseline_offset = point(px(0.), padding_top + layout.ascent); let baseline_offset = point(px(0.), padding_top + layout.ascent);
@ -225,7 +218,7 @@ fn paint_line(
origin, origin,
align_width.unwrap_or(layout.width), align_width.unwrap_or(layout.width),
px(0.0), px(0.0),
&text_align, &align,
layout, layout,
wraps.peek(), wraps.peek(),
), ),
@ -276,7 +269,7 @@ fn paint_line(
origin, origin,
align_width.unwrap_or(layout.width), align_width.unwrap_or(layout.width),
glyph.position.x, glyph.position.x,
&text_align, &align,
layout, layout,
wraps.peek(), wraps.peek(),
); );
@ -299,44 +292,30 @@ fn paint_line(
} }
if let Some(style_run) = style_run { if let Some(style_run) = style_run {
let mut run_color = style_run.color;
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.and_then(|s| s.color) {
run_color = val;
}
if let Some(val) = text_style.and_then(|s| s.underline.as_ref()) {
run_underline = Some(val);
}
if let Some(val) = text_style.and_then(|s| s.strikethrough) {
run_strikethrough = Some(val);
}
if let Some((_, underline_style)) = &mut current_underline { if let Some((_, underline_style)) = &mut current_underline {
if style_run.underline.as_ref() != Some(underline_style) { if style_run.underline.as_ref() != Some(underline_style) {
finished_underline = current_underline.take(); finished_underline = current_underline.take();
} }
} }
if let Some(run_underline) = run_underline.as_ref() { if let Some(run_underline) = style_run.underline.as_ref() {
current_underline.get_or_insert(( current_underline.get_or_insert((
point( point(
glyph_origin.x, glyph_origin.x,
glyph_origin.y + baseline_offset.y + (layout.descent * 0.618), glyph_origin.y + baseline_offset.y + (layout.descent * 0.618),
), ),
UnderlineStyle { UnderlineStyle {
color: Some(run_underline.color.unwrap_or(run_color)), color: Some(run_underline.color.unwrap_or(style_run.color)),
thickness: run_underline.thickness, thickness: run_underline.thickness,
wavy: run_underline.wavy, wavy: run_underline.wavy,
}, },
)); ));
} }
if let Some((_, strikethrough_style)) = &mut current_strikethrough { if let Some((_, strikethrough_style)) = &mut current_strikethrough {
if run_strikethrough.as_ref() != Some(strikethrough_style) { if style_run.strikethrough.as_ref() != Some(strikethrough_style) {
finished_strikethrough = current_strikethrough.take(); finished_strikethrough = current_strikethrough.take();
} }
} }
if let Some(mut run_strikethrough) = run_strikethrough.as_ref() { if let Some(run_strikethrough) = style_run.strikethrough.as_ref() {
current_strikethrough.get_or_insert(( current_strikethrough.get_or_insert((
point( point(
glyph_origin.x, glyph_origin.x,
@ -344,14 +323,14 @@ fn paint_line(
+ (((layout.ascent * 0.5) + baseline_offset.y) * 0.5), + (((layout.ascent * 0.5) + baseline_offset.y) * 0.5),
), ),
StrikethroughStyle { StrikethroughStyle {
color: Some(run_strikethrough.color.unwrap_or(run_color)), color: Some(run_strikethrough.color.unwrap_or(style_run.color)),
thickness: run_strikethrough.thickness, thickness: run_strikethrough.thickness,
}, },
)); ));
} }
run_end += style_run.len as usize; run_end += style_run.len as usize;
color = run_color; color = style_run.color;
} else { } else {
run_end = layout.len; run_end = layout.len;
finished_underline = current_underline.take(); finished_underline = current_underline.take();