From a01bc8f89eec9d91c4bdf2442d2cd3e8c00d604a Mon Sep 17 00:00:00 2001 From: Zaxaerith Date: Thu, 3 Dec 2026 16:19:47 +0800 Subject: [PATCH] shape: clear the gallery icon tag after Change Shape (#2557) --- crates/engine/src/cmd/shape/appearance.rs | 2 + crates/engine/src/icons.rs | 48 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/crates/engine/src/cmd/shape/appearance.rs b/crates/engine/src/cmd/shape/appearance.rs index c736beb78..43d60f3e9 100644 --- a/crates/engine/src/cmd/shape/appearance.rs +++ b/crates/engine/src/cmd/shape/appearance.rs @@ -68,6 +68,8 @@ pub(super) fn change(s: &mut Session, p: &Value) -> Result { let info = deckcraft_geom::preset::info(name).ok_or_else(|| bad("shape.change", format!("unknown preset `{name}`")))?; edit_geometry(s, p, "shape.change", |sh| { sh.geom = Geom::preset(info.name); + let (tag, value) = crate::icons::INSERTED_ICON_TAG; + sh.tags.retain(|(key, tag_value)| key != tag || tag_value != value); Ok(()) }) } diff --git a/crates/engine/src/icons.rs b/crates/engine/src/icons.rs index ea66dbf5d..3fac77535 100644 --- a/crates/engine/src/icons.rs +++ b/crates/engine/src/icons.rs @@ -255,6 +255,54 @@ mod tests { } } + #[test] + fn change_shape_clears_icon_identity_until_undone() { + let mut s = Session::with_new(); + let insert_icon = |s: &mut Session| s.execute("insert.icon", &json!({"name": "star"})).unwrap()["id"].as_u64().unwrap(); + let missing = insert_icon(&mut s); + let described = insert_icon(&mut s); + let untouched = insert_icon(&mut s); + let targets = json!({"ids": [missing, described]}); + crate::cmd::edit_shapes(&mut s, &targets, "shape.change", |shape| { + shape.tags.push(("CUSTOM_TAG".into(), "kept".into())); + Ok(()) + }) + .unwrap(); + s.execute("shape.altText", &json!({"ids": [described], "text": "Five-point outline"})).unwrap(); + + let missing_alt = |s: &mut Session| { + s.execute("review.accessibility", &json!({})) + .unwrap() + .as_array() + .unwrap() + .iter() + .filter(|issue| issue["issue"] == "Missing alternative text") + .map(|issue| issue["shape"].as_u64().unwrap()) + .collect::>() + }; + let shapes = |s: &Session| [missing, described].map(|id| s.doc().unwrap().shape(ShapeId(id as u32)).unwrap().clone()); + assert_eq!(missing_alt(&mut s), [missing, untouched]); + let original = shapes(&s); + let selection = s.doc().unwrap().selection.shapes.clone(); + let converted = original.clone().map(|mut shape| { + shape.geom = Geom::preset("ellipse"); + shape.tags = vec![("CUSTOM_TAG".into(), "kept".into())]; + shape + }); + + s.execute("shape.change", &json!({"ids": [missing, described], "preset": "ellipse"})).unwrap(); + assert_eq!(shapes(&s), converted); + assert_eq!(s.doc().unwrap().selection.shapes, selection); + assert_eq!(missing_alt(&mut s), [untouched]); + + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(shapes(&s), original); + assert_eq!(missing_alt(&mut s), [missing, untouched]); + s.execute("edit.redo", &json!({})).unwrap(); + assert_eq!(shapes(&s), converted); + assert_eq!(missing_alt(&mut s), [untouched]); + } + fn ink_in(img: &deckcraft_render::Image, x: f64, y: f64, w: f64, h: f64, scale: f64) -> usize { let x0 = (x * scale).floor().max(0.0) as u32; let y0 = (y * scale).floor().max(0.0) as u32;