fix(clipboard): paste copies dimensions correctly (#290)

Copy-paste (CTRL+C / CTRL+V) dropped dimensions. A dimension draws from
its baked *D block, whose geometry is in absolute WCS coordinates, and
the clipboard paste path added the dimension entity but never gave it its
own transformed block — unlike the in-drawing COPY, which does (#161). So
the pasted dimension kept pointing at the source block and rendered at
the original location instead of the paste point (same drawing), or had
no block at all (cross-drawing).

Capture each copied dimension's *D block into the clipboard, and on paste
build a fresh transformed copy of it and re-point the dimension's
block_name — for same- and cross-drawing pastes alike. Factored the
block-building out of clone_transformed_block into a shared
define_transformed_block, and the block snapshotting out of
capture_blocks into snapshot_block.
This commit is contained in:
sLuCHa 2026-07-07 15:53:21 +02:00
commit c20f277e54
3 changed files with 121 additions and 34 deletions

View file

@ -223,7 +223,26 @@ impl Scene {
.iter()
.find(|br| br.name.eq_ignore_ascii_case(src_name))
.map(|br| br.entity_handles.clone())?;
if sub_handles.is_empty() {
let subs: Vec<EntityType> = sub_handles
.iter()
.filter_map(|&sh| self.document.get_entity(sh).cloned())
.collect();
self.define_transformed_block(&subs, t)
}
/// Build a fresh anonymous `*D<n>` block from `subs` — a source block's
/// sub-entities in its own (WCS-baked) coordinates — transforming each by
/// `t`, and return the new block's name. Shared by the in-drawing copy
/// (source block still lives in this document, via `clone_transformed_block`)
/// and clipboard paste (source block snapshotted into the clipboard, so a
/// pasted dimension gets its own transformed block cross-drawing too — see
/// `finalize_paste`, #290). Returns None when `subs` is empty.
pub(crate) fn define_transformed_block(
&mut self,
subs: &[EntityType],
t: &EntityTransform,
) -> Option<String> {
if subs.is_empty() {
return None;
}
// Smallest free `*D<n>` anonymous name.
@ -252,14 +271,13 @@ impl Scene {
block_end.common.handle = end_handle;
block_end.common.owner_handle = br_handle;
self.document.add_entity(EntityType::BlockEnd(block_end)).ok()?;
for sh in sub_handles {
if let Some(mut sub) = self.document.get_entity(sh).cloned() {
view::dispatch::apply_transform(&mut sub, t);
Self::reset_clone_subhandles(&mut self.document, &mut sub);
sub.common_mut().handle = Handle::NULL;
sub.common_mut().owner_handle = br_handle;
let _ = self.document.add_entity(sub);
}
for sub in subs {
let mut sub = sub.clone();
view::dispatch::apply_transform(&mut sub, t);
Self::reset_clone_subhandles(&mut self.document, &mut sub);
sub.common_mut().handle = Handle::NULL;
sub.common_mut().owner_handle = br_handle;
let _ = self.document.add_entity(sub);
}
Some(new_name)
}