fix(group): preserve groups when pasting, cross-drawing too

PR #446 kept a fully-copied group grouped for the in-drawing COPY/ARRAY
path, but clipboard paste (Ctrl+C / Ctrl+V, PASTECLIP) runs through
finalize_paste, a separate route that never touched groups — so pasted
copies came out ungrouped, and a cross-drawing paste had no group data at
all.

Unify all copy routes on one shared Scene::recreate_groups(sources,
handle_map): copy_complete_groups now gathers the live source groups and
delegates to it, while paste snapshots the complete groups into the
clipboard at copy time (ClipboardDeps.groups) and recreates them over the
pasted handles. A group whose whole membership is copied now stays grouped
whether the copy lands in the same drawing, via the clipboard, or in a
different file; partially-selected groups still stay ungrouped.

Closes #440

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-23 15:09:06 +03:00
commit f1a348260f
3 changed files with 76 additions and 8 deletions

View file

@ -2492,6 +2492,22 @@ impl OpenCADStudio {
})
.collect();
self.merge_clipboard_ext_objects(i, &by_index);
// Recreate any group whose whole membership was copied, so a pasted
// group stays grouped — cross-drawing too, since the groups were
// snapshotted into the clipboard at copy time. `by_index` is aligned
// with `self.clipboard`, so the source handle of each pasted entity maps
// its clipboard clone to its new handle. Same shared `recreate_groups`
// the in-drawing COPY path uses. (#440)
if !self.clipboard_deps.groups.is_empty() {
let mut handle_map = rustc_hash::FxHashMap::default();
for (src, &new) in self.clipboard.iter().zip(by_index.iter()) {
if !new.is_null() {
handle_map.insert(src.common().handle, new);
}
}
let groups = self.clipboard_deps.groups.clone();
self.tabs[i].scene.recreate_groups(groups, &handle_map);
}
// Incremental: `add_entity` already tessellated every pasted top-level
// solid, and existing document solids are still cached — so only newly
// introduced block-definition solids need building. The full rebuild