From b0223ac0e584c363df7a3587617c084c8dd7882d Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 28 Aug 2026 12:37:18 +0200 Subject: [PATCH] :bug: Align WASM auto-width text size with HTML measurement Add the 1px right margin used by the HTML `.paragraph-set` renderer when reporting auto-width dimensions from Skia, so stored selrects match get-text-dimensions and stale-text sync does not misfire. --- render-wasm/src/shapes/text.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/render-wasm/src/shapes/text.rs b/render-wasm/src/shapes/text.rs index 3bc29e96fd..1d9244dd95 100644 --- a/render-wasm/src/shapes/text.rs +++ b/render-wasm/src/shapes/text.rs @@ -51,6 +51,11 @@ pub struct TextContentSize { const DEFAULT_TEXT_CONTENT_SIZE: f32 = 0.01; +/// Matches `marginRight: "1px"` on `.paragraph-set` in the HTML text renderer +/// (`frontend/src/app/main/ui/shapes/text/styles.cljs`). DOM `getBoundingClientRect` +/// includes that margin in auto-width measurements; Skia `longest_line()` does not. +const PARAGRAPH_SET_MARGIN_RIGHT: f32 = 1.0; + impl TextContentSize { pub fn default() -> Self { Self { @@ -770,7 +775,7 @@ impl TextContent { let measure_paragraphs = build_paragraphs_from_paragraph_builders(&mut measure_builders, f32::MAX); - let width = measure_paragraphs + let content_width = measure_paragraphs .iter() .flatten() .fold(0.0_f32, |auto_width, paragraph| { @@ -778,9 +783,10 @@ impl TextContent { }) .ceil(); - // Re-layout at that width with the real alignment. + // Re-layout at the intrinsic width (without the HTML margin slack). let mut paragraph_builders = self.paragraph_builder_group_from_text(None); - let paragraphs = build_paragraphs_from_paragraph_builders(&mut paragraph_builders, width); + let paragraphs = + build_paragraphs_from_paragraph_builders(&mut paragraph_builders, content_width); let height = paragraphs .iter() .flatten() @@ -788,10 +794,11 @@ impl TextContent { auto_height + paragraph.height() }); + let reported_width = content_width + PARAGRAPH_SET_MARGIN_RIGHT; let size = TextContentSize::new_with_normalized_line_height( - width, + reported_width, height.ceil(), - width, + reported_width, normalized_line_height, ); TextContentLayoutResult(paragraph_builders, paragraphs, size)