From 07664847bdc70e5b98b472985204b9ccd4d40f8c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 04:24:11 -0800 Subject: [PATCH] Type: text.setStyle refuses a leading with trailing text `leading: "12abc"` set 12 pt leading and returned success, while `size` and `tracking` in the same command refused trailing text. `leading` now reads its value with `length_given`, so a string must be a whole number or a length with a unit. The error message is unchanged. --- crates/engine/src/cmd/typecmd.rs | 6 ++++-- crates/engine/src/tests/textedit.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/typecmd.rs b/crates/engine/src/cmd/typecmd.rs index 48959c54e2..6d29550fa0 100644 --- a/crates/engine/src/cmd/typecmd.rs +++ b/crates/engine/src/cmd/typecmd.rs @@ -8,7 +8,7 @@ use vectorcraft_doc::{AreaFit, Document, Justify, Node, NodeId, NodeKind, RubyAl use vectorcraft_geom::{Affine, PathData, Vec2}; use super::edit::selected_roots; -use super::pathops::{len_param, length_given, number_given, shape_node}; +use super::pathops::{length_given, number_given, shape_node}; use super::{ CommandSpec, EngineError, Result, Session, bad, check_numbers, cmd, color_value, f64_req, has_doc, has_selection, id_param, index, number_or, ok, str_param, switch_or, targets, text_param, @@ -824,7 +824,9 @@ fn set_style(s: &mut Session, p: &Value) -> Result { let leading = match p.get("leading") { None | Some(Value::Null) => None, Some(Value::String(a)) if a.eq_ignore_ascii_case("auto") => Some(None), - Some(_) => Some(Some(len_param(p, "leading").ok_or_else(|| bad(C, "leading must be a number or \"auto\""))?.clamp(0.1, 5000.0))), + Some(_) => { + Some(Some(length_given(p, "leading", C).ok().flatten().ok_or_else(|| bad(C, "leading must be a number or \"auto\""))?.clamp(0.1, 5000.0))) + } }; let tracking = number_given(p, "tracking", C)?; let justify = match text_param(p, "justify", C)? { diff --git a/crates/engine/src/tests/textedit.rs b/crates/engine/src/tests/textedit.rs index 4447946190..f49a88c80b 100644 --- a/crates/engine/src/tests/textedit.rs +++ b/crates/engine/src/tests/textedit.rs @@ -522,6 +522,7 @@ fn character_ruby_and_path_handle_refuse_a_param_of_the_wrong_type() { ("text.setStyle", json!({"size": 30, "justify": {"value": "center"}}), string("justify")), ("text.setStyle", json!({"features": ["dlig", 5]}), tags.clone()), ("text.setStyle", json!({"leading": true}), "leading must be a number or \"auto\"".to_string()), + ("text.setStyle", json!({"leading": "12abc"}), "leading must be a number or \"auto\"".to_string()), ("text.setRangeStyle", json!({"id": id.0, "font": 5}), string("font")), ("text.setRangeStyle", json!({"id": id.0, "size": 30, "style": false}), string("style")), ("text.setRangeStyle", json!({"id": id.0, "features": [null]}), tags),