mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Vector Halftone: the dialog matches Custom in any letter case
The effect reads the style case-insensitively, but the dialog compared it to "custom" exactly. A stored "CUSTOM" hid the Shape and Angle rows and OK left both keys out. The dialog now compares with eq_ignore_ascii_case in both places, with a test for an uppercase "CUSTOM".
This commit is contained in:
@@ -59,7 +59,7 @@ pub(crate) fn screen_params(live: bool, fields: &DialogFields) -> Vec<Param> {
|
||||
let styles =
|
||||
[("custom", "Custom"), ("grid", "Grid"), ("gridAngle", "Grid Angle"), ("gridDots", "Grid Dots"), ("gridDotsAngle", "Grid Dots Angle")];
|
||||
// A named style sets the shape and the angle, so their rows show only for Custom.
|
||||
let custom = fields.text("style").is_none_or(|s| s == "custom");
|
||||
let custom = fields.text("style").is_none_or(|s| s.eq_ignore_ascii_case("custom"));
|
||||
let mut rows = vec![Param::new("style", tl!("Style"), ParamKind::choice(options(&styles), Some("custom".into())))];
|
||||
if custom {
|
||||
rows.push(Param::new("shape", tl!("Shape"), ParamKind::choice(options(&shapes), Some("circle".into()))));
|
||||
@@ -130,7 +130,7 @@ pub(crate) fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
/// Angle are left out so that the style's own shape and angle apply.
|
||||
pub(crate) fn command_params(fields: &DialogFields) -> serde_json::Map<String, Value> {
|
||||
let mut params = json_of(&screen_params(false, fields), fields);
|
||||
if params.get("style").and_then(Value::as_str).is_some_and(|s| s != "custom") {
|
||||
if params.get("style").and_then(Value::as_str).is_some_and(|s| !s.eq_ignore_ascii_case("custom")) {
|
||||
params.remove("shape");
|
||||
params.remove("angle");
|
||||
}
|
||||
@@ -310,6 +310,20 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// A stored style matches Custom in any letter case, as the effect reads it, so Shape and
|
||||
/// Angle stay on screen and OK sends both.
|
||||
#[test]
|
||||
fn custom_style_in_any_case_keeps_shape_and_angle() {
|
||||
let mut values = fields();
|
||||
values["style"] = json!("CUSTOM");
|
||||
let f = fields_of(&screen_params(false, &DialogFields::new()), values.as_object().unwrap());
|
||||
let rows = screen_params(false, &f);
|
||||
let shown = |k: &str| rows.iter().any(|p| p.key == k);
|
||||
assert!(shown("shape") && shown("angle"), "Shape and Angle rows are hidden");
|
||||
let sent = command_params(&f);
|
||||
assert!(sent.contains_key("shape") && sent.contains_key("angle"), "{sent:?}");
|
||||
}
|
||||
|
||||
/// With Preview off, OK after File > Revert is refused and leaves the restored drawing as it is.
|
||||
#[test]
|
||||
fn vector_halftone_without_preview_refuses_ok_after_file_revert() {
|
||||
|
||||
Reference in New Issue
Block a user