From 88e0fe6f888a64f1b0951dd453d561082c0f16dd Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 29 Nov 2021 11:28:43 -0800 Subject: [PATCH] Paint highlighted lines correctly when horizontally scrolled --- crates/gpui/src/text_layout.rs | 44 +++++++++++++--------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/crates/gpui/src/text_layout.rs b/crates/gpui/src/text_layout.rs index 105dae7c92..9c975ea491 100644 --- a/crates/gpui/src/text_layout.rs +++ b/crates/gpui/src/text_layout.rs @@ -259,31 +259,18 @@ impl Line { for glyph in &run.glyphs { let glyph_origin = origin + baseline_offset + glyph.position; - - if glyph_origin.x() + max_glyph_width < visible_bounds.origin().x() { - continue; - } if glyph_origin.x() > visible_bounds.upper_right().x() { break; } + let mut finished_underline = None; if glyph.index >= run_end { if let Some((run_len, run_color, run_underline_color)) = style_runs.next() { - if let Some((underline_origin, underline_color)) = underline { + if let Some((_, underline_color)) = underline { if *run_underline_color != Some(underline_color) { - cx.scene.push_underline(scene::Quad { - bounds: RectF::from_points( - underline_origin, - glyph_origin + vec2f(0., 1.), - ), - background: Some(underline_color), - border: Default::default(), - corner_radius: 0., - }); - underline = None; + finished_underline = underline.take(); } } - if let Some(run_underline_color) = run_underline_color { underline.get_or_insert((glyph_origin, *run_underline_color)); } @@ -293,20 +280,23 @@ impl Line { } else { run_end = self.layout.len; color = Color::black(); - if let Some((underline_origin, underline_color)) = underline.take() { - cx.scene.push_underline(scene::Quad { - bounds: RectF::from_points( - underline_origin, - glyph_origin + vec2f(0., 1.), - ), - background: Some(underline_color), - border: Default::default(), - corner_radius: 0., - }); - } + finished_underline = underline.take(); } } + if glyph_origin.x() + max_glyph_width < visible_bounds.origin().x() { + continue; + } + + if let Some((underline_origin, underline_color)) = finished_underline { + cx.scene.push_underline(scene::Quad { + bounds: RectF::from_points(underline_origin, glyph_origin + vec2f(0., 1.)), + background: Some(underline_color), + border: Default::default(), + corner_radius: 0., + }); + } + cx.scene.push_glyph(scene::Glyph { font_id: run.font_id, font_size: self.layout.font_size,