From 97a5bc1d39caab3d2a677e3b89f169f390f6db60 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Mon, 28 Sep 2026 19:35:19 +0300 Subject: [PATCH] fix(offset): the offset just created can be hovered and offset again A running command only knew the entities that existed when it started; committed results are now handed back to it, and OFFSET adds them to its pick set. Fixes #673 Co-Authored-By: Claude Opus 5.5 --- src/app/command_driver/entity_commit.rs | 14 ++++++++++++++ src/command.rs | 6 ++++++ src/modules/draw/modify/offset.rs | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/src/app/command_driver/entity_commit.rs b/src/app/command_driver/entity_commit.rs index 588023fa4..2fcb4e256 100644 --- a/src/app/command_driver/entity_commit.rs +++ b/src/app/command_driver/entity_commit.rs @@ -62,6 +62,7 @@ impl OpenCADStudio { } if let Some(handle) = committed { self.apply_continuous_constraints(i, &[handle]); + self.notify_entities_committed(i, &[handle]); } self.tabs[i].dirty = true; let prompt = self.tabs[i].active_cmd.as_ref().map(|c| c.prompt()); @@ -123,6 +124,7 @@ impl OpenCADStudio { committed.extend(handle); } self.apply_continuous_constraints(i, &committed); + self.notify_entities_committed(i, &committed); self.tabs[i].dirty = true; self.tabs[i].scene.clear_preview_wire(); let prompt = self.tabs[i].active_cmd.as_ref().map(|c| c.prompt()); @@ -135,6 +137,18 @@ impl OpenCADStudio { None } + /// Hand the stored copies of freshly committed entities to the command + /// that is still running. + fn notify_entities_committed(&mut self, i: usize, handles: &[codec::Handle]) { + let entities: Vec = handles + .iter() + .filter_map(|handle| self.tabs[i].scene.document.get_entity(*handle).cloned()) + .collect(); + if let Some(command) = self.tabs[i].active_cmd.as_mut() { + command.on_entities_committed(&entities); + } + } + pub(super) fn handle_commit_entities_and_exit( &mut self, mut entities: Vec, diff --git a/src/command.rs b/src/command.rs index b99a48bd4..922d64abd 100644 --- a/src/command.rs +++ b/src/command.rs @@ -2688,6 +2688,12 @@ pub trait CadCommand: Send { /// Commands that stay active across replaces should update their internal snapshots here. fn on_entity_replaced(&mut self, _old: Handle, _new_handles: &[Handle]) {} + /// Called after `CmdResult::CommitEntity` / `CommitEntities` added + /// entities while the command stays active, with the entities as stored + /// (fresh handles). Commands that pick from a snapshot add them here so + /// their own results can be hovered and picked next. (#673) + fn on_entities_committed(&mut self, _entities: &[codec::EntityType]) {} + /// Called after a PEDIT operation changed its target. fn on_pedit_applied(&mut self) {} diff --git a/src/modules/draw/modify/offset.rs b/src/modules/draw/modify/offset.rs index 9dfccfe76..be4a901b2 100644 --- a/src/modules/draw/modify/offset.rs +++ b/src/modules/draw/modify/offset.rs @@ -818,6 +818,11 @@ impl CadCommand for OffsetCommand { } } + fn on_entities_committed(&mut self, entities: &[EntityType]) { + self.all_entities.extend(entities.iter().cloned()); + self.entity_index = ModifyEntityIndex::build(&self.all_entities); + } + fn on_hover_entity(&mut self, handle: Handle, _pt: DVec3) -> Vec { if handle.is_null() || !matches!(self.step, Step::SelectObject { .. }) { return vec![];