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.
This commit is contained in:
dotCooCoo committed 2026-11-25 19:24:38 -08:00
1 parent 67e6f0466e
commit d07ca8514c
2 files changed
+30 -1

No files matched your search

+3 -1
View File
@@ -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> {
+27
View File
@@ -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]