From f03288f120e82452c930af96cab62597ed2ffbd2 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Tue, 21 Jul 2026 11:06:42 +0300 Subject: [PATCH] fix(bedit): restore the view when leaving the block editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Entering the block editor reframes the camera on the block's own geometry, but nothing remembered where the model view was — Save / Discard returned to the layout with the camera still parked at the editor's framing (#425). The session now captures the camera on entry and both exits restore it exactly. Co-Authored-By: Claude Fable 5 --- src/app/commands/inquiry.rs | 10 ++++++++++ src/modules/draw/modify/block_edit.rs | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/commands/inquiry.rs b/src/app/commands/inquiry.rs index 07532c75b..b6558fcea 100644 --- a/src/app/commands/inquiry.rs +++ b/src/app/commands/inquiry.rs @@ -385,6 +385,9 @@ impl OpenCADStudio { self.push_undo_snapshot(i, "BEDIT"); let return_layout = self.tabs[i].scene.current_layout.clone(); + // Capture the camera before the editor reframes it, so leaving + // the block editor returns the view exactly where it was (#425). + let return_camera = self.tabs[i].scene.camera.borrow().clone(); // A block editor renders in model style; switch to Model first so // the paper-space code paths stay off, then scope to the block. if return_layout != "Model" { @@ -396,6 +399,7 @@ impl OpenCADStudio { br_handle, return_layout, snapshot, + return_camera, }); self.tabs[i].scene.deselect_all(); @@ -426,6 +430,9 @@ impl OpenCADStudio { self.tabs[i].scene.block_edit_block = None; self.tabs[i].scene.deselect_all(); self.tabs[i].scene.set_current_layout(session.return_layout.clone()); + // Return the view to where it was when BEDIT began (#425). + *self.tabs[i].scene.camera.borrow_mut() = session.return_camera.clone(); + self.tabs[i].scene.camera_generation += 1; self.tabs[i].scene.rebuild_derived_caches(); self.tabs[i].dirty = true; self.command_line.push_output(&format!( @@ -474,6 +481,9 @@ impl OpenCADStudio { self.tabs[i].scene.block_edit_block = None; self.tabs[i].scene.deselect_all(); self.tabs[i].scene.set_current_layout(session.return_layout.clone()); + // Return the view to where it was when BEDIT began (#425). + *self.tabs[i].scene.camera.borrow_mut() = session.return_camera.clone(); + self.tabs[i].scene.camera_generation += 1; self.tabs[i].scene.rebuild_derived_caches(); self.tabs[i].dirty = true; self.command_line.push_output(&format!( diff --git a/src/modules/draw/modify/block_edit.rs b/src/modules/draw/modify/block_edit.rs index 8b2d88657..2bb271e40 100644 --- a/src/modules/draw/modify/block_edit.rs +++ b/src/modules/draw/modify/block_edit.rs @@ -43,7 +43,7 @@ pub fn block_edit_tools() -> Vec { // ── Session state (held in DocumentTab) ─────────────────────────────────── /// Active BEDIT block-editor session. Lives in `DocumentTab::block_edit`. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct BlockEditSession { /// Name of the block being edited (also the space-tab label). pub block_name: String, @@ -55,6 +55,9 @@ pub struct BlockEditSession { /// The block's block-local entities captured on entry, so Discard can /// restore the definition (structural Block/BlockEnd/AttDef excluded). pub snapshot: Vec, + /// Camera state of the space that was active when BEDIT began, restored + /// on Save/Discard so the view returns exactly where it was (#425). + pub return_camera: crate::scene::view::camera::Camera, } // ── BEDIT pick command ─────────────────────────────────────────────────────