From a469cd309b1742398d0598ca5f2b80b1a7eae37b Mon Sep 17 00:00:00 2001 From: Pierre Le Fevre Date: Thu, 5 Mar 2026 21:26:44 +0100 Subject: [PATCH] Fix inline background insertion order in paint_text When both underline and background were present, bg_idx pointed to the underline rect instead of the DrawGlyphs command, causing the background to paint after the text. Capture glyph_idx before pushing any commands to ensure correct painter's order. Co-Authored-By: Claude Opus 4.6 --- crates/render/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index d0b1619..c437827 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -125,10 +125,13 @@ fn paint_borders(layout_box: &LayoutBox, list: &mut DisplayList) { fn paint_text(layout_box: &LayoutBox, list: &mut DisplayList) { for line in &layout_box.lines { - // Use per-fragment styling from the TextLine. let color = line.color; let font_size = line.font_size; + // Record index before pushing glyphs so we can insert the background + // before the text in painter's order. + let glyph_idx = list.len(); + list.push(PaintCommand::DrawGlyphs { line: line.clone(), font_size, @@ -150,12 +153,8 @@ fn paint_text(layout_box: &LayoutBox, list: &mut DisplayList) { // Draw inline background if not transparent. if line.background_color.a > 0 && line.width > 0.0 { - // Insert background before the text (painter's order). - // We add it at the end for simplicity; a real implementation - // would insert before the DrawGlyphs. - let bg_idx = list.len() - 1; // Index of the DrawGlyphs we just pushed. list.insert( - bg_idx, + glyph_idx, PaintCommand::FillRect { x: line.x, y: line.y, -- 2.51.2