From c192dfbd768c28ffb4427301cdfa12c4abdefdcf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 10:51:29 -0800 Subject: [PATCH] Preserve explicit preference edits and refresh Apply baselines --- crates/ui-egui/src/prefs_dialog.rs | 30 ++++++++- crates/ui-egui/src/prefs_dialog/model.rs | 29 ++++++++- crates/ui-egui/src/prefs_dialog/tests.rs | 78 ++++++++++++++++++++++++ docs/mcp.md | 9 ++- docs/target-app-parity.md | 2 +- 5 files changed, 139 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs index a5040f5022..8724cbe520 100644 --- a/crates/ui-egui/src/prefs_dialog.rs +++ b/crates/ui-egui/src/prefs_dialog.rs @@ -105,6 +105,26 @@ impl PrefsWindow { self.touched.remove(key); } + fn explicitly_edited(&self, key: &str) -> bool { + if self.touched.contains(key) { + return true; + } + let (now, opened) = (self.draft.get::(key), self.opened.get::(key)); + match (now.as_ref().and_then(Value::as_f64), opened.as_ref().and_then(Value::as_f64)) { + (Some(a), Some(b)) => a != b, + _ => now != opened, + } + } + + fn read_external(&mut self, key: &str, value: &Value) { + if self.explicitly_edited(key) { + self.source.set(key, value); + } else { + self.read(key, value); + self.opened.set(key, value); + } + } + /// Sets the row `key` in the window, as the user or a reset does. fn set_row(&mut self, key: &str, value: &Value) { self.draft.set(key, value); @@ -127,6 +147,7 @@ impl PrefsWindow { for (k, v) in prefs.as_object().into_iter().flatten() { if self.draft.get::(k).is_some() { self.read(k, v); + self.opened.set(k, v); } } self.reset_units = self.draft.get::("unitsGeneral"); @@ -408,7 +429,7 @@ fn apply_prefs_resets_to(app: &mut VectorcraftApp, mut w: Option<&mut PrefsWindo } // The window shows the reset row, so OK keeps it. if let Some(w) = w.as_deref_mut() { - w.read(key, &json!(value)); + w.read_external(key, &json!(value)); } } // And the reset preferences, the groups with a reset of every category; Units ▸ General then leaves the open @@ -419,8 +440,9 @@ fn apply_prefs_resets_to(app: &mut VectorcraftApp, mut w: Option<&mut PrefsWindo for (k, v) in prefs.as_object().into_iter().flatten() { let reset = spec(k).map_or(every && PREF_GROUPS.contains(&k.as_str()), |s| in_reset(s.category)); if reset && w.draft.get::(k).is_some() { - w.read(k, v); - if k == "unitsGeneral" { + let edited = w.explicitly_edited(k); + w.read_external(k, v); + if k == "unitsGeneral" && !edited { w.reset_units = v.as_str().map(str::to_string); } } @@ -429,7 +451,9 @@ fn apply_prefs_resets_to(app: &mut VectorcraftApp, mut w: Option<&mut PrefsWindo } // The Edit Original row shows the app's Edit Original choice. if spec("editOriginalSystemDefaults").is_some_and(|s| in_reset(s.category)) { + let before = app.ui.original_editor.clone(); crate::original_editor::reset_saved(app); + app.prefs_changed |= before != app.ui.original_editor; } true } diff --git a/crates/ui-egui/src/prefs_dialog/model.rs b/crates/ui-egui/src/prefs_dialog/model.rs index ef8197ba08..af35fcdb84 100644 --- a/crates/ui-egui/src/prefs_dialog/model.rs +++ b/crates/ui-egui/src/prefs_dialog/model.rs @@ -427,8 +427,20 @@ impl PreferencesDraft for Live<'_> { // A `prefs.reset` run since the last frame shows in the draft before OK reads it. super::apply_prefs_resets_to(self.app, Some(&mut *self.w)); // Only the rows changed in the window: a setting changed outside it while it is open keeps its new value. - let edited: Map = - self.w.draft.to::>().unwrap_or_default().into_iter().filter(|(k, _)| self.w.edited(k)).collect(); + let current = self.app.session.prefs.to_json(); + let edited: Map = self + .w + .draft + .to::>() + .unwrap_or_default() + .into_iter() + .filter(|(k, _)| { + self.w.edited(k) + && (k != "keyHoldDelay" + || self.w.explicitly_edited(k) + || current.get(k).and_then(Value::as_f64) == self.w.source.get::(k).as_ref().and_then(Value::as_f64)) + }) + .collect(); let values: Map = edited.iter().filter(|(k, _)| !k.starts_with("__")).map(|(k, v)| (k.clone(), v.clone())).collect(); let touch_ws = values.get("touchWorkspace").and_then(Value::as_bool); let document_units = self.w.reset_units.as_deref().is_none_or(|u| values.get("unitsGeneral").and_then(Value::as_str) != Some(u)); @@ -463,10 +475,23 @@ impl PreferencesDraft for Live<'_> { } // The row shows the task bar in use: after OK enters Touch, that is Touch's, not the value the workspace left // took, so a later Apply does not give the workspace left's value to Touch. + let current = self.app.session.prefs.to_json(); + for (key, value) in current.as_object().into_iter().flatten() { + if self.w.draft.get::(key).is_some() { + self.w.draft.set(key, value); + } + } + if let Some(state) = self.app.session.active() { + self.w.draft.set("unitsGeneral", &state.doc.units.key()); + } + self.w.draft.set("__smartGuides", &self.app.ui.view.smart_guides); + self.w.draft.set("__snapToGrid", &self.app.ui.view.snap_to_grid); self.w.draft.set("__taskBar", &self.app.ui.task_bar); self.w.opened = self.w.draft.clone(); self.w.source = self.w.draft.clone(); self.w.touched.clear(); + self.w.reset_units = None; + self.w.sync_strings(); Ok(()) } diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index af3e9487cb..b4e3b3843f 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -61,6 +61,84 @@ fn field(a: &VectorcraftApp, key: &str) -> Value { fields(a).and_then(|f| f.get(key).cloned()).unwrap_or(Value::Null) } +#[test] +fn applying_a_reset_allows_a_later_explicit_document_units_edit() { + use craft::ui::patterns::preferences::PreferencesDraft as _; + let mut a = app(); + a.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + a.run("document.setUnits", json!({"units": "Inches"})).unwrap(); + open(&mut a, Some("General")); + reset_preferences(&mut a, PromptChoice::Proceed); + let mut window = a.prefs.take().unwrap(); + model::Live { app: &mut a, w: &mut window }.apply().unwrap(); + a.prefs = Some(window); + assert_eq!(a.session.active().unwrap().doc.units, vectorcraft_doc::Unit::Inches); + set_field(&mut a, "unitsGeneral", json!("points")).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.active().unwrap().doc.units, vectorcraft_doc::Unit::Points); +} + +#[test] +fn imported_rows_follow_a_later_external_reset() { + let mut a = app(); + open(&mut a, Some("General")); + let data = json!({"format": "vectorcraft-preferences", "version": 1, "prefs": {"keyboardIncrement": 7}}).to_string(); + a.run("prefs.import", json!({"data": data})).unwrap(); + a.run("prefs.reset", json!({"category": "General"})).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.keyboard_increment, Prefs::default().keyboard_increment); +} + +#[test] +fn a_command_changed_delay_survives_opening_time_normalization() { + let mut a = app(); + a.session.prefs.key_hold_delay = 5.0; + open(&mut a, Some("General")); + a.run("prefs.set", json!({"key": "keyHoldDelay", "value": 0.6})).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.key_hold_delay, 0.6); +} + +#[test] +fn an_external_reset_keeps_rows_edited_in_preferences() { + let mut a = app(); + open(&mut a, Some("General")); + set_field(&mut a, "keyboardIncrement", json!(9)).unwrap(); + let smart = !a.ui.view.smart_guides; + set_field(&mut a, "__smartGuides", json!(smart)).unwrap(); + a.run("prefs.reset", json!({})).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.keyboard_increment, 9.0); + assert_eq!(a.ui.view.smart_guides, smart); +} + +#[test] +fn an_external_editor_reset_requests_a_settings_save() { + let mut a = app(); + a.ui.original_editor = serde_json::from_value(json!({"path": "editor"})).unwrap(); + a.prefs_changed = false; + a.session.execute("prefs.reset", &json!({"category": "File Handling"})).unwrap(); + a.prefs_changed = false; + apply_prefs_resets(&mut a); + assert!(a.prefs_changed); +} + +#[test] +fn apply_refreshes_untouched_rows_from_current_preferences() { + use craft::ui::patterns::preferences::PreferencesDraft as _; + let mut a = app(); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap(); + open(&mut a, Some("General")); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 9})).unwrap(); + set_field(&mut a, "constrainAngle", json!(30)).unwrap(); + let mut w = a.prefs.take().unwrap(); + model::Live { app: &mut a, w: &mut w }.apply().unwrap(); + assert_eq!(w.draft.get::("keyboardIncrement"), Some(json!(9.0))); + assert_eq!(w.opened.get::("keyboardIncrement"), Some(json!(9.0))); + assert_eq!(w.source.get::("keyboardIncrement"), Some(json!(9.0))); + assert!(!w.edited("keyboardIncrement")); +} + /// One row per kind is saved by OK: the model's value conversion reaches `prefs.set` for each. #[test] fn ok_saves_every_row_kind() { diff --git a/docs/mcp.md b/docs/mcp.md index cf426c00e1..d2c53c2d7b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9358,8 +9358,11 @@ as it was, and `ui.dialog.confirm` shows it again with every preference at its d Preferences. `prefs.reset` resets the preferences at once, without the question. OK in Preferences writes only the fields changed in the dialog since it opened or since its last Apply, so a preference, Smart Guides, Snap to Grid, Enable Contextual Task Bar or the document's units changed some other way while it is open (a command, a panel menu, -a script) keeps its new value. A field changed both ways takes the dialog's value. OK with no field changed writes -nothing and adds no undo step. +a script) keeps its new value when its dialog field is unchanged. A field changed both ways takes the dialog's value. +An opening-time correction of Hold Shortcut Delay does not overwrite a later command change. Apply refreshes the +dialog's baseline from the current preferences and UI values. OK also saves an opening-time Hold Shortcut Delay +correction when no later command changed that value. With no field change or delay correction, OK writes nothing +and adds no undo step. ```json {"name":"run_command","arguments":{"command":"prefs.set","params":{"key":"unitsGeneral","value":"millimeters"}}} @@ -9368,7 +9371,7 @@ nothing and adds no undo step. Reset Preferences also sets the dialog's `__smartGuides`, `__snapToGrid` and `__taskBar` fields to their defaults (`__taskBar` takes the value the current workspace was saved with). A category's own reset sets the field of that category (Smart Guides, Guides & Grid or General), and File Handling's also resets the app chosen for Edit Original. -`prefs.reset` run while Preferences is open shows the values it reset in the dialog. In the app, `prefs.reset` also resets Smart Guides, +`prefs.reset` run while Preferences is open updates its unchanged fields and preserves edits in the dialog. In the app, `prefs.reset` also resets Smart Guides, Snap to Grid and Enable Contextual Task Bar when it resets every category or their category (Smart Guides, Guides & Grid and General), and the app chosen for Edit Original when it resets every category or File Handling. A `category` left out or `null` resets every category, and one that is not a string is an error. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 7fbbf7c200..cdd0bb8796 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -910,7 +910,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Preferences search:** a Search Preferences field above the category list has the keyboard focus when the dialog opens, and Cmd/Ctrl+F gives it back; typing lists the settings it finds, and choosing one shows its category, as the [help page](https://helpx.adobe.com/illustrator/desktop/get-started/preferences-and-settings/set-app-preferences.html) describes. VectorCraft's own rules: the field matches a setting's label, section or category, ignoring case, in the interface language or in English; the list replaces the categories while the field has text and shows every match, or "No settings found"; the chosen setting's row is highlighted and scrolled into view; Escape in the field with text clears it, and Escape in the empty field closes the dialog. The dialog's `__search` field (`ui.dialog.set`) holds the text. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`. - **Reset Preferences asks first (#6435):** the Preferences dialog's Reset Preferences button opens a question over the dialog (`resetPreferences`). Cancel or Escape goes back to Preferences unchanged, with its category, search and edits kept; OK goes back with every preference at its default value, which OK in Preferences applies and Cancel there discards. The question and its wording are VectorCraft's own. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`. - **Reset Preferences resets every setting the dialog shows:** Smart Guides and Snap to Grid also return to their defaults (on and off) when Reset Preferences is confirmed, and General's Enable Contextual Task Bar takes the value the current workspace was saved with. OK in Preferences applies them with the other defaults, and Cancel keeps the values in use. A category's own reset resets the row of that category, and File Handling's also resets the app chosen for Edit Original. `prefs.reset` (the Command Palette's Reset Preferences) resets them too, each only when it resets every category or the setting's own, and with every category or File Handling it also clears the app chosen for Edit Original. The rule is VectorCraft's own. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`, `crates/ui-egui/src/original_editor.rs`. -- **Preferences OK keeps changes made outside the dialog:** OK writes only the settings changed in the dialog, so a preference, Smart Guides, Snap to Grid, Enable Contextual Task Bar or the document's units changed by a command or a script while Preferences is open keeps its new value, and a workspace switched to while it is open keeps its own Contextual Task Bar. OK with nothing changed writes nothing. The rule is VectorCraft's own. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`. +- **Preferences OK keeps changes made outside the dialog:** OK preserves command or script changes to fields left unchanged in the dialog, including preferences, Smart Guides, Snap to Grid, Enable Contextual Task Bar and document units. A field edited in both places takes the dialog's value. OK saves an opening-time Hold Shortcut Delay correction unless a later command changed that value. An external reset preserves dialog edits, and Apply refreshes the baseline from current preferences and UI values. A workspace switched to while the dialog is open keeps its own Contextual Task Bar. With no field change or delay correction, OK writes nothing. The rule is VectorCraft's own. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`. - **Preferences › General describes its settings:** the line under the Preferences fields shows a sentence for each of the 32 General settings, Enable Contextual Task Bar included, when the pointer is over the setting's row or its control has the keyboard focus, and a screen reader gets the same sentence. The sentences are VectorCraft's own and state what the app does with each setting. Sentences: `crates/ui-egui/src/prefs_dialog/descriptions.rs`. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`. - **Preferences › Selection & Anchor Display describes its settings:** the line under the Preferences fields shows a sentence for each of the 14 Selection & Anchor Display settings, from Tolerance to the Curvature Tool rubber band, on hover and on keyboard focus, and a screen reader gets the same sentence. The Snap to Point sentence states that the Smart Guides Snapping Tolerance applies while Smart Guides is on. Sentences: `crates/ui-egui/src/prefs_dialog/descriptions.rs`. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`. - **Preferences › Guides & Grid describes its settings:** the line under the Preferences fields shows a sentence for each of the 12 Guides & Grid settings, from Snap to Grid to Pattern Editing's Tile Edge Color, on hover and on keyboard focus, and a screen reader gets the same sentence. The Show Pixel Grid sentence states that the pixel grid shows from 600% zoom. Sentences: `crates/ui-egui/src/prefs_dialog/descriptions.rs`. Tests: `crates/ui-egui/src/prefs_dialog/tests.rs`.