From 8d6e21ef5f0be42ca139a1e8717c9ae7529a88e0 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sun, 14 Jun 2026 00:16:06 +0300 Subject: [PATCH] fix(layers): sync header CLAYER when making a layer current (#93) Making a layer current via the layer manager (LayerSetCurrent) or LAYMCUR updated only the per-tab active_layer, not the document header's current_layer_name/handle. The no-selection ribbon refresh reads the header layer, so after the change an Esc (deselect -> refresh_properties) snapped the active-layer dropdown back to the stale header value ("0") even though new entities still used the correct active layer. Mirror the change into the header in both paths, matching the ribbon dropdown's own set-current path. Co-Authored-By: Claude Opus 4.8 --- src/app/commands.rs | 14 ++++++++++++++ src/app/update.rs | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/app/commands.rs b/src/app/commands.rs index 0b21100fe..1305a31f1 100644 --- a/src/app/commands.rs +++ b/src/app/commands.rs @@ -232,9 +232,23 @@ impl OpenCADStudio { self.tabs[i].active_cmd = Some(Box::new(cmd)); } else { let layer = entities[0].1.common().layer.clone(); + // Keep the document header (CLAYER) in sync, not just the + // per-tab default, so a later no-selection ribbon refresh + // (e.g. after Esc) doesn't snap back to the stale header + // layer. See #93. + let handle = self.tabs[i] + .scene + .document + .layers + .get(&layer) + .map(|l| l.handle) + .unwrap_or(acadrust::types::Handle::NULL); + self.tabs[i].scene.document.header.current_layer_name = layer.clone(); + self.tabs[i].scene.document.header.current_layer_handle = handle; self.tabs[i].active_layer = layer.clone(); self.ribbon.active_layer = layer.clone(); self.tabs[i].layers.current_layer = layer.clone(); + self.tabs[i].dirty = true; self.command_line .push_info(&format!("Current layer set to \"{layer}\".")); self.refresh_layer_panel(); diff --git a/src/app/update.rs b/src/app/update.rs index 0ce27ff3a..b880c9a68 100644 --- a/src/app/update.rs +++ b/src/app/update.rs @@ -1826,8 +1826,22 @@ impl OpenCADStudio { if let Some(idx) = self.tabs[i].layers.selected { if let Some(layer) = self.tabs[i].layers.layers.get(idx) { let name = layer.name.clone(); + // Mirror the change into the document header (CLAYER) too, + // not just the per-tab default. Otherwise the no-selection + // ribbon refresh (e.g. after Esc) re-reads the stale header + // layer and the dropdown snaps back to it. See #93. + let handle = self.tabs[i] + .scene + .document + .layers + .get(&name) + .map(|l| l.handle) + .unwrap_or(acadrust::types::Handle::NULL); + self.tabs[i].scene.document.header.current_layer_name = name.clone(); + self.tabs[i].scene.document.header.current_layer_handle = handle; self.tabs[i].active_layer = name.clone(); self.tabs[i].layers.current_layer = name.clone(); + self.tabs[i].dirty = true; self.ribbon.active_layer = name; } }