mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-28 03:57:44 -06:00
#1061: Enter renames the selected effect, text animator, mask or shape group
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
470ea7a3af
commit
42c7a7141e
@@ -2,7 +2,7 @@
|
||||
//! effect, mask, shape item or text animator (what scripting's `PropertyGroup.name`, `enabled`,
|
||||
//! `remove()`, `duplicate()` and `moveTo()` do, and what agents need without a UI selection).
|
||||
|
||||
use effectcraft_project::{GroupKind, ItemId, LayerId, LayerSource, Node, PropGroup, Uid};
|
||||
use effectcraft_project::{ItemId, LayerId, LayerSource, Node, PropGroup, Uid};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{CommandSpec, b_p, bad, has_layers, layer_mut, layer_p, layers_p, str_p};
|
||||
@@ -10,7 +10,7 @@ use crate::{EngineError, Result, Session, cmd};
|
||||
|
||||
/// Groups that can be renamed, removed, duplicated and reordered: instances in indexed lists.
|
||||
fn is_instance(g: &PropGroup) -> bool {
|
||||
matches!(g.kind, GroupKind::Indexed | GroupKind::Effect { .. } | GroupKind::Mask { .. } | GroupKind::Tracker { .. })
|
||||
g.is_instance()
|
||||
}
|
||||
|
||||
/// `{layer, prop: uid}` → (comp, layer, group uid), checking that the group is an instance.
|
||||
|
||||
@@ -167,3 +167,26 @@ fn delete_removes_selected_groups_not_their_layer() {
|
||||
delete(&mut s);
|
||||
assert!(s.active_comp().unwrap().layer(LayerId(t)).is_none(), "a fixed group selected: the layer goes");
|
||||
}
|
||||
|
||||
/// #1061: text animators, masks and shape groups rename like effects, with undo; fixed groups and
|
||||
/// empty names are refused.
|
||||
#[test]
|
||||
fn text_animators_masks_and_shape_groups_rename() {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "C", "width": 64, "height": 64, "duration": 1})).unwrap();
|
||||
let t = s.execute("layer.newText", json!({"text": "ABCD"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.addTextAnimator", json!({"layer": t, "properties": ["tracking"]})).unwrap();
|
||||
let sh = s.execute("layer.newShape", json!({"kind": "star"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.addMask", json!({"layer": sh, "shape": "ellipse"})).unwrap();
|
||||
let uid = |s: &Session, l: u64, path: &str| s.active_comp().unwrap().layer(LayerId(l)).unwrap().props.group(path).unwrap().groups().next().unwrap().uid;
|
||||
let name = |s: &Session, l: u64, u: u64| s.active_comp().unwrap().layer(LayerId(l)).unwrap().props.find_group(u).unwrap().name.clone();
|
||||
for (l, path, new) in [(t, "text/animators", "Wiggle In"), (sh, "masks", "Reveal"), (sh, "contents", "Star Body")] {
|
||||
let u = uid(&s, l, path);
|
||||
let old = name(&s, l, u);
|
||||
s.execute("prop.renameGroup", json!({"layer": l, "prop": u, "name": new})).unwrap();
|
||||
assert_eq!(name(&s, l, u), new, "{path}");
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(name(&s, l, u), old, "{path} undone");
|
||||
assert!(s.execute("prop.renameGroup", json!({"layer": l, "prop": u, "name": " "})).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user