New comps from footage get a unique name, as Duplicate does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Themolx
2026-10-12 14:22:59 +02:00
co-authored by Claude Opus 5.5
parent 9efe75330c
commit 9e66e0d2ec
5 changed files with 70 additions and 8 deletions
+1 -6
View File
@@ -108,12 +108,7 @@ fn new_comp(s: &mut Session, p: &Value) -> Result<Value> {
}
apply_settings(&mut c, p);
let id = s.edit("New Composition", None, |proj, st| {
let mut name = name.clone();
let mut k = 2;
while proj.items.values().any(|i| i.name == name) {
name = format!("{} {k}", name.trim_end_matches(|ch: char| ch.is_ascii_digit()).trim_end());
k += 1;
}
let name = proj.unique_item_name(&name, |_| false);
let id = proj.add_item(&name, Label::Sandstone, None, ItemKind::Comp(c.into()));
st.project_selection = vec![id];
Ok(id)
+4
View File
@@ -207,6 +207,10 @@ fn new_comp_from_selection(s: &mut Session, p: &Value) -> Result<Value> {
let name = lead.name.rsplit_once('.').map(|(a, _)| a.to_string()).unwrap_or(lead.name.clone());
let c = Comp { pixel_aspect, ..Comp::new(w.max(1), h.max(1), rate, dur) };
let cid = s.edit("New Comp from Selection", None, |proj, st| {
// A name another item already has gets the next free number, as Duplicate gives
// ("clip", "clip 2", "clip 3"). The comp's own footage and solid sources don't
// count, so an extensionless one still names its first comp; a source comp does.
let name = proj.unique_item_name(&name, |i| g.contains(&i.id) && !matches!(i.kind, ItemKind::Comp(_)));
let cid = proj.add_item(&name, Label::Sandstone, None, ItemKind::Comp(c.into()));
st.project_selection = vec![cid];
Ok(cid)
+1 -2
View File
@@ -219,8 +219,7 @@ fn duplicate(s: &mut Session, p: &Value) -> Result<Value> {
if it.is_folder() {
return Err(bad(c, "folders can't be duplicated"));
}
let base = it.name.trim_end_matches(|ch: char| ch.is_ascii_digit()).trim_end().to_string();
let name = (2..).map(|i| format!("{base} {i}")).find(|n| proj.find_by_name(n).is_none()).unwrap_or_default();
let name = proj.numbered_item_name(&it.name, |_| false);
let mut kind = it.kind.clone();
if let effectcraft_project::ItemKind::Comp(comp) = &mut kind {
let comp = std::sync::Arc::make_mut(comp);