From d07ca8514cec3512133d5998b7702b8ac99ae71c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 19:24:38 -0800 Subject: [PATCH] Preferences: Apply is enabled for a reset of a row a command changed A reset in Preferences can leave a row showing the value the window opened with after a command changed the setting. OK wrote that row, but Apply stayed disabled because it compared the draft only with the values at open. Apply is now enabled while any row has been set in the window. --- crates/ui-egui/src/prefs_dialog/model.rs | 4 +++- crates/ui-egui/src/prefs_dialog/tests.rs | 27 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/prefs_dialog/model.rs b/crates/ui-egui/src/prefs_dialog/model.rs index 32408bf5c8..ef8197ba08 100644 --- a/crates/ui-egui/src/prefs_dialog/model.rs +++ b/crates/ui-egui/src/prefs_dialog/model.rs @@ -417,8 +417,10 @@ impl PreferencesModel for Live<'_> { } impl PreferencesDraft for Live<'_> { + /// A row set in the window counts even when it shows the value it opened with: a reset of a row a command changed + /// while the window is open is still applied. fn differs(&self) -> bool { - self.w.draft != self.w.opened + self.w.draft != self.w.opened || !self.w.touched.is_empty() } fn apply(&mut self) -> Result<(), String> { diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index ed34d2c53c..948baf7f2d 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -641,6 +641,33 @@ fn ok_keeps_settings_changed_by_commands_while_preferences_is_open() { assert_eq!(a.session.prefs.keyboard_increment, default, "the reset is written"); } +/// A reset in Preferences that leaves a row showing the value it opened with, after a command changed the setting, +/// still enables Apply, and Apply writes it. +#[test] +fn apply_writes_a_reset_of_a_row_a_command_changed() { + use craft::ui::patterns::preferences::PreferencesDraft as _; + let live = |a: &mut VectorcraftApp, apply: bool| { + let mut w = a.prefs.take().expect("Preferences is open"); + let mut m = model::Live { app: &mut *a, w: &mut w }; + let differs = m.differs(); + if apply { + m.apply().unwrap(); + } + a.prefs = Some(w); + differs + }; + let mut a = app(); + let on = a.ui.view.smart_guides; + open(&mut a, Some("General")); + assert!(!live(&mut a, false), "nothing to apply at open"); + a.run("view.smartGuides", json!({})).unwrap(); + reset_preferences(&mut a, PromptChoice::Proceed); + assert_eq!(field(&a, "__smartGuides"), json!(on), "the row shows the value it opened with"); + assert!(live(&mut a, true), "Apply is enabled"); + assert_eq!(a.ui.view.smart_guides, on, "Apply writes the reset"); + assert!(!live(&mut a, false), "nothing left to apply"); +} + /// OK with nothing changed in Preferences writes nothing: no preference, no undo step in the document and no save /// of the settings. #[test]