mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-04 22:50:29 +00:00
shape: clear the gallery icon tag after Change Shape (#2557)
This commit is contained in:
@@ -68,6 +68,8 @@ pub(super) fn change(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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(())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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::<Vec<_>>()
|
||||
};
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user