diff --git a/crates/gpui/examples/text_layout.rs b/crates/gpui/examples/text_layout.rs index c4cbcd4e5edc142dde58a1dd5d9b61a1daee0c3a..8929955ba824c36c90951ece2cf9ba710259ddac 100644 --- a/crates/gpui/examples/text_layout.rs +++ b/crates/gpui/examples/text_layout.rs @@ -1,6 +1,6 @@ use gpui::{ - App, Application, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px, - size, + App, Application, Bounds, Context, FontStyle, FontWeight, StyledText, Window, WindowBounds, + WindowOptions, div, prelude::*, px, size, }; struct HelloWorld {} @@ -71,6 +71,12 @@ impl Render for HelloWorld { .child("100%"), ), ) + .child(div().flex().gap_2().justify_between().child( + StyledText::new("ABCD").with_highlights([ + (0..1, FontWeight::EXTRA_BOLD.into()), + (2..3, FontStyle::Italic.into()), + ]), + )) } } diff --git a/crates/gpui/src/text_system.rs b/crates/gpui/src/text_system.rs index 3de6e639b585bbe52e8d215065dceed6308781e3..2e233a53022d0a1dfa9ed3164b2d67b6ff465819 100644 --- a/crates/gpui/src/text_system.rs +++ b/crates/gpui/src/text_system.rs @@ -424,7 +424,6 @@ impl WindowTextSystem { font_runs.clear(); let line_end = line_start + line_text.len(); - let mut last_font: Option = None; let mut decoration_runs = SmallVec::<[DecorationRun; 32]>::new(); let mut run_start = line_start; while run_start < line_end { @@ -453,14 +452,13 @@ impl WindowTextSystem { true }; + let font_id = self.resolve_font(&run.font); if let Some(font_run) = font_runs.last_mut() - && Some(font_run.font_id) == last_font + && font_id == font_run.font_id && !decoration_changed { font_run.len += run_len_within_line; } else { - let font_id = self.resolve_font(&run.font); - last_font = Some(font_id); font_runs.push(FontRun { len: run_len_within_line, font_id,