From d3db02de9ae83a38ca57e96a38553d49c8568d97 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 26 Oct 2026 23:04:38 +0700 Subject: [PATCH] #1378: max lines only while truncation is ENDING, with a REST test for auto height with truncation off --- crates/format/src/rest/tests.rs | 11 +++++++++++ crates/format/src/rest/text.rs | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/format/src/rest/tests.rs b/crates/format/src/rest/tests.rs index f9acf2ea..5ea5264f 100644 --- a/crates/format/src/rest/tests.rs +++ b/crates/format/src/rest/tests.rs @@ -365,6 +365,17 @@ fn text_styles_and_runs() { assert!(!named(&doc, "NoFills").fills.is_empty(), "text keeps its default fill"); } +#[test] +fn max_lines_apply_only_while_truncating() { + let (doc, _) = one(json!([ + {"id": "1", "name": "Auto", "type": "TEXT", "relativeTransform": at(0.0, 0.0), "size": {"x": 100, "y": 20}, "characters": "a", + "style": {"textAutoResize": "HEIGHT", "textTruncation": "DISABLED", "maxLines": 2}} + ])); + let NodeKind::Text(td) = &named(&doc, "Auto").kind else { panic!() }; + assert_eq!((td.auto_resize, td.max_lines), (TextAutoResize::Height, 0)); + assert!(!td.truncates()); +} + #[test] fn auto_layout_constraints_and_grids() { let (doc, _) = one(json!([ diff --git a/crates/format/src/rest/text.rs b/crates/format/src/rest/text.rs index 46dc7486..18e5015e 100644 --- a/crates/format/src/rest/text.rs +++ b/crates/format/src/rest/text.rs @@ -69,9 +69,11 @@ fn paragraph(s: &Value, td: &mut TextData) { // Missing means a fixed box. _ => TextAutoResize::None, }; - td.max_lines = num(s, "maxLines").filter(|n| *n >= 1.0).map_or(0, |n| n.min(10_000.0) as u32); + // A line limit applies only while truncation is on; a leftover `maxLines` is ignored. + let ending = text(s, "textTruncation") == Some("ENDING"); + td.max_lines = num(s, "maxLines").filter(|n| ending && *n >= 1.0).map_or(0, |n| n.min(10_000.0) as u32); // Auto height with a line limit keeps hugging its lines up to the limit. - if text(s, "textTruncation") == Some("ENDING") && !td.truncates() { + if ending && !td.truncates() { td.auto_resize = TextAutoResize::Truncate; } td.paragraph_spacing = len(s, "paragraphSpacing").unwrap_or(0.0);