mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-17 23:56:17 +00:00
Fix #2904: a second layer or a copy of v-b1.mp4 is v-b1.mp4 2, not v-b1.mp 2
Comp::unique_layer_name and Project::numbered_item_name each stripped every trailing digit before numbering. Both use one helper now, numbered_name, which replaces a trailing number only when a space sets it off (Red Solid 1 -> Red Solid 2); digits that end a word stay.
This commit is contained in:
1 parent
a646bdcc2e
commit
0b60a86bfe
3 files changed
+48
-12
No files matched your search
@@ -265,13 +265,11 @@ impl Comp {
|
||||
self.layers.iter().find(|l| matches!(l.source, LayerSource::Camera) && l.switches.video && l.is_active_at(t))
|
||||
}
|
||||
|
||||
/// Unique layer name with a numeric suffix (`Shape Layer 2`).
|
||||
/// `base`, or the next free numbered name when a layer already has it (`Shape Layer 2`,
|
||||
/// `v-b1.mp4 2`; see `numbered_name`).
|
||||
pub fn unique_layer_name(&self, base: &str) -> String {
|
||||
if !self.layers.iter().any(|l| l.name == base) {
|
||||
return base.to_string();
|
||||
}
|
||||
let stem = base.trim_end_matches(|c: char| c.is_ascii_digit()).trim_end();
|
||||
(2..).map(|i| format!("{stem} {i}")).find(|n| !self.layers.iter().any(|l| &l.name == n)).unwrap_or_default()
|
||||
let taken = |n: &str| self.layers.iter().any(|l| l.name == n);
|
||||
if taken(base) { crate::item::numbered_name(base, taken) } else { base.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user