Merge pull request #263 from zed-industries/fix-highlighting-when-x-scrolled

Paint highlighted lines correctly when horizontally scrolled
This commit is contained in:
Max Brunsfeld 2021-11-29 11:43:08 -08:00 committed by GitHub
commit 29b616f4cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,31 +259,18 @@ impl Line {
for glyph in &run.glyphs { for glyph in &run.glyphs {
let glyph_origin = origin + baseline_offset + glyph.position; 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() { if glyph_origin.x() > visible_bounds.upper_right().x() {
break; break;
} }
let mut finished_underline = None;
if glyph.index >= run_end { if glyph.index >= run_end {
if let Some((run_len, run_color, run_underline_color)) = style_runs.next() { 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) { if *run_underline_color != Some(underline_color) {
cx.scene.push_underline(scene::Quad { finished_underline = underline.take();
bounds: RectF::from_points(
underline_origin,
glyph_origin + vec2f(0., 1.),
),
background: Some(underline_color),
border: Default::default(),
corner_radius: 0.,
});
underline = None;
} }
} }
if let Some(run_underline_color) = run_underline_color { if let Some(run_underline_color) = run_underline_color {
underline.get_or_insert((glyph_origin, *run_underline_color)); underline.get_or_insert((glyph_origin, *run_underline_color));
} }
@ -293,19 +280,22 @@ impl Line {
} else { } else {
run_end = self.layout.len; run_end = self.layout.len;
color = Color::black(); color = Color::black();
if let Some((underline_origin, underline_color)) = underline.take() { 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 { cx.scene.push_underline(scene::Quad {
bounds: RectF::from_points( bounds: RectF::from_points(underline_origin, glyph_origin + vec2f(0., 1.)),
underline_origin,
glyph_origin + vec2f(0., 1.),
),
background: Some(underline_color), background: Some(underline_color),
border: Default::default(), border: Default::default(),
corner_radius: 0., corner_radius: 0.,
}); });
} }
}
}
cx.scene.push_glyph(scene::Glyph { cx.scene.push_glyph(scene::Glyph {
font_id: run.font_id, font_id: run.font_id,