From ba8aed4fada493c11c94286189423556c7505f95 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sat, 3 Oct 2026 15:01:45 +0300 Subject: [PATCH] fix(dynmode): one toggle keeps DYNMODE's sign in step F12, the drafting dialog and restored settings each re-derived DYNMODE and lost the mode on the way: F12 off set 0, so on came back as 3 even after DYNMODE 1. set_dyn_input now makes off negative (temporarily off) and on restore the stored mode, and the bare query prints the stored value. Co-Authored-By: Claude Opus 5.5 --- src/app/commands/styleprops.rs | 15 ++++----------- src/app/drafting_settings.rs | 19 +++++++++++++------ src/app/update/file.rs | 4 ++-- src/app/update/mod.rs | 7 +------ 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/app/commands/styleprops.rs b/src/app/commands/styleprops.rs index 8051eed84..c669354e8 100644 --- a/src/app/commands/styleprops.rs +++ b/src/app/commands/styleprops.rs @@ -1713,14 +1713,7 @@ impl OpenCADStudio { } _ => Err("SETVAR: integer from -3 to 3 required.".into()), }, - None => { - let mode = if self.dyn_input { - if self.dyn_mode > 0 { self.dyn_mode } else { 3 } - } else { - if self.dyn_mode <= 0 { self.dyn_mode } else { 0 } - }; - Ok((format!("DYNMODE = {mode}"), false)) - } + None => Ok((format!("DYNMODE = {}", self.dyn_mode), false)), }, "ZOOMWHEEL" => match &value { Some(v) => match parse_bool(v) { @@ -3838,14 +3831,14 @@ mod tests { assert_eq!(app.dyn_mode, 1); assert!(app.dyn_input); - // F12 / Message::ToggleDynInput synchronization + // F12 turns it off temporarily (negative) and restores the mode. let _ = app.update(crate::app::Message::ToggleDynInput); assert!(!app.dyn_input); - assert_eq!(app.dyn_mode, 0); + assert_eq!(app.dyn_mode, -1); let _ = app.update(crate::app::Message::ToggleDynInput); assert!(app.dyn_input); - assert_eq!(app.dyn_mode, 3); + assert_eq!(app.dyn_mode, 1); } } diff --git a/src/app/drafting_settings.rs b/src/app/drafting_settings.rs index 2b8b7369f..058fff8ab 100644 --- a/src/app/drafting_settings.rs +++ b/src/app/drafting_settings.rs @@ -44,6 +44,18 @@ impl DraftingSettingsState { } impl OpenCADStudio { + /// Turn Dynamic Input on or off with DYNMODE in step: off keeps the mode + /// negative (temporarily off), on restores it, or 3 when there was none. + pub(in crate::app) fn set_dyn_input(&mut self, on: bool) { + self.dyn_input = on; + let mode = self.dyn_mode.abs(); + self.dyn_mode = match (on, mode) { + (true, 0) => 3, + (true, mode) => mode, + (false, mode) => -mode, + }; + } + pub(super) fn drafting_settings_dirty(&self) -> bool { match (&self.drafting_settings_state, &self.drafting_settings_saved) { (Some(curr), Some(saved)) => curr.is_dirty(saved), @@ -100,12 +112,7 @@ impl OpenCADStudio { self.snapper.enabled = state.snap_modes.clone(); self.snapper.snap3d_enabled = state.osnap3d_on; self.snapper.enabled3d = state.snap3d_modes.clone(); - self.dyn_input = state.dyn_input_on; - if self.dyn_input && self.dyn_mode <= 0 { - self.dyn_mode = 3; - } else if !self.dyn_input && self.dyn_mode > 0 { - self.dyn_mode = 0; - } + self.set_dyn_input(state.dyn_input_on); self.quick_properties = state.quick_props_on; self.selection_cycling = state.selection_cycling_on; self.sync_vport_display(self.active_tab); diff --git a/src/app/update/file.rs b/src/app/update/file.rs index 1aaa47170..167e39c7e 100644 --- a/src/app/update/file.rs +++ b/src/app/update/file.rs @@ -750,8 +750,8 @@ impl OpenCADStudio { /// Apply restored preferences to live state. pub(in crate::app) fn apply_settings(&mut self, s: &crate::app::settings::UserSettings) { - self.dyn_input = s.dyn_input; - self.dyn_mode = if s.dyn_mode != 0 { s.dyn_mode } else if s.dyn_input { 3 } else { 0 }; + self.dyn_mode = s.dyn_mode; + self.set_dyn_input(s.dyn_input); self.polar_mode = s.polar; self.polar_increment_deg = s.polar_increment_deg; self.zoom_wheel_reversed = s.zoom_wheel_reversed; diff --git a/src/app/update/mod.rs b/src/app/update/mod.rs index c6680d3ad..70c160a1b 100644 --- a/src/app/update/mod.rs +++ b/src/app/update/mod.rs @@ -4196,12 +4196,7 @@ impl OpenCADStudio { Task::none() } Message::ToggleDynInput => { - self.dyn_input ^= true; - if self.dyn_input && self.dyn_mode <= 0 { - self.dyn_mode = 3; - } else if !self.dyn_input && self.dyn_mode > 0 { - self.dyn_mode = 0; - } + self.set_dyn_input(!self.dyn_input); Task::none() } Message::ToggleViewCube => {