diff --git a/crates/engine/src/cmd/format.rs b/crates/engine/src/cmd/format.rs index 0336dc41f..83ec891b3 100644 --- a/crates/engine/src/cmd/format.rs +++ b/crates/engine/src/cmd/format.rs @@ -422,6 +422,24 @@ mod tests { } } + #[test] + fn font_dialog_ok_accepts_preset_and_system_names_it_does_not_know() { + use deckcraft_color::Rgba; + let last = Rgba::rgb(0x12, 0x34, 0x56); + let preset = ColorRef { base: ColorBase::Preset { name: "notAColor".into() }, mods: vec![] }.with(ColorTransform::LumMod(50_000)); + let system = ColorRef { base: ColorBase::System { name: "notAColor".into(), last }, mods: vec![] }; + for (color, drawn) in [(preset, ColorRef::rgb(Rgba::BLACK).with(ColorTransform::LumMod(50_000))), (system, ColorRef::rgb(last))] { + let mut s = shape(); + let fill = Fill::Solid { color }; + format_run(&mut s, &|r| r.fill = Some(fill.clone())).unwrap(); + s.ui_requests.clear(); + s.execute("format.fontDialog", &json!({})).unwrap(); + let Some(UiRequest::Dialog { params, .. }) = s.ui_requests.last().cloned() else { panic!("dialog request") }; + s.execute("format.fontDialog", &json!({"color": params["color"], "size": 20.0})).unwrap(); + assert_eq!(props(&s).fill, Some(Fill::Solid { color: drawn }), "{}", params["color"]); + } + } + #[test] fn font_dialog_color_mods_round_trip_and_unknown_ops_are_errors() { let two = ColorRef { base: ColorBase::Preset { name: "red".into() }, mods: vec![] } diff --git a/crates/engine/src/cmd/format/font.rs b/crates/engine/src/cmd/format/font.rs index 57fd81c34..82d47568e 100644 --- a/crates/engine/src/cmd/format/font.rs +++ b/crates/engine/src/cmd/format/font.rs @@ -396,7 +396,14 @@ fn color_command_value(c: &deckcraft_model::ColorRef) -> Value { } // `#RRGGBB`, or `#RRGGBBAA` for a color that is not opaque. let hex = |c: &deckcraft_color::Rgba| if c.a == 255 { format!("#{}", c.hex()) } else { format!("#{}{:02X}", c.hex(), c.a) }; - match &c.base { + // A preset or system name that `color_value` does not know (kept from an opened file) is given as + // the color it is drawn with, so OK does not reject it. + let base = match &c.base { + ColorBase::Preset { name } if !deckcraft_color::is_preset_name(name) => ColorBase::Rgb { rgb: deckcraft_color::Rgba::BLACK }, + ColorBase::System { name, last } if !deckcraft_color::is_system_name(name) => ColorBase::Rgb { rgb: *last }, + b => b.clone(), + }; + match &base { ColorBase::Rgb { rgb } if o.is_empty() => json!(hex(rgb)), ColorBase::Rgb { rgb } => { o.insert("rgb".into(), json!(hex(rgb)));