From dceb9626ae5917c288d897b99a2dfae7d5475234 Mon Sep 17 00:00:00 2001 From: Karim Jerbi Date: Wed, 12 Aug 2026 23:10:01 +0100 Subject: [PATCH] fix(dock): block palette reflects new blocks without reopening Creating a block from selected entities now bumps the geometry epoch, so the block palette's per-update stale check notices the new definition and refreshes its list in place instead of requiring the user to close and reopen the panel. --- src/app/update/dialog.rs | 43 ++++++++++++++++++++++++++++++++++++++++ src/scene/entity.rs | 7 ++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/app/update/dialog.rs b/src/app/update/dialog.rs index fb87dbfa5..403959ecb 100644 --- a/src/app/update/dialog.rs +++ b/src/app/update/dialog.rs @@ -1039,6 +1039,49 @@ mod tests { assert_eq!(app.block_palette.placing.as_deref(), Some("Fixture")); } + #[test] + fn blockpalette_reflects_new_block_without_reopen() { + use acadrust::types::Transform; + + let mut app = fresh(); + let i = app.active_tab; + + // Reproduce the user-facing flow: select entities and run the BLOCK + // command, which goes through `create_block_from_entities` (not the + // clipboard / paste-as-block path). + let mut line = Line::new(); + line.start = Vector3::ZERO; + line.end = Vector3::new(10.0, 0.0, 0.0); + let first = app.tabs[i].scene.add_entity(EntityType::Line(line)); + app.tabs[i].scene.select_entity(first, false); + app.show_block_palette = true; + let ws = Transform::identity(); + let id = Transform::identity(); + app.tabs[i] + .scene + .create_block_from_entities(&[first], "First", &ws, &id) + .unwrap(); + app.refresh_block_palette_if_stale(); + assert!(app.block_palette.blocks.iter().any(|b| b.name == "First")); + + // Create a second block on the same tab, then re-run the per-update + // stale check. It must pick up the new block WITHOUT reopening. + line = Line::new(); + line.start = Vector3::ZERO; + line.end = Vector3::new(9.0, 0.0, 0.0); + let second = app.tabs[i].scene.add_entity(EntityType::Line(line)); + app.tabs[i].scene.select_entity(second, false); + app.tabs[i] + .scene + .create_block_from_entities(&[second], "Second", &ws, &id) + .unwrap(); + app.refresh_block_palette_if_stale(); + assert!( + app.block_palette.blocks.iter().any(|b| b.name == "Second"), + "Second must appear without reopening the panel" + ); + } + #[test] fn blockpalette_pin_toggles_autocollapse_and_close_hides() { let mut app = fresh(); diff --git a/src/scene/entity.rs b/src/scene/entity.rs index b19b57807..4a1b5f2f0 100644 --- a/src/scene/entity.rs +++ b/src/scene/entity.rs @@ -698,7 +698,12 @@ impl Scene { let mut insert = DxfInsert::new(name, acadrust::types::Vector3::ZERO); acadrust::Entity::apply_transform(&mut insert, block_to_world); - Ok(self.add_entity(EntityType::Insert(insert))) + let insert_handle = self.add_entity(EntityType::Insert(insert)); + // A new block definition landed in the document; advance the block + // epoch so consumers (the block palette stale check) notice it even + // when the panel stays open. Mirrors `define_block_from_owned_entities`. + self.bump_geometry(); + Ok(insert_handle) } /// Define a new block named `name` from `entities` (owned, not yet in the