From 9d34e458c102bc2e1dd6e2843ba6618672f41e81 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 18:36:28 -0800 Subject: [PATCH 1/3] Preferences: OK writes only the settings changed in the dialog OK sent every row of the draft through prefs.set and wrote Smart Guides, Snap to Grid and Enable Contextual Task Bar back from the values copied when the dialog opened. A setting changed by a command, a panel menu or a script while Preferences was open went back to its old value, and a workspace switched to while it was open took the Contextual Task Bar of the workspace the dialog opened in. - The window keeps each row as it last read it (at open, after an import or a prefs.reset refreshes it, and after OK or Apply) and the rows set in it since then. OK and Apply write only the rows set in the window or whose value differs from the one read, so a reset in the window is still written. A row changed both ways takes the window's value. - Enable Contextual Task Bar left alone in the dialog is not written, so each workspace keeps its own bar. - OK with nothing changed runs no prefs.set, adds no undo step and does not ask the host to save the settings; original_editor::commit reports whether the Edit Original choice changed. Docs: docs/mcp.md (Preferences) and a line in docs/target-app-parity.md. --- crates/ui-egui/src/original_editor.rs | 7 +- crates/ui-egui/src/prefs_dialog.rs | 62 +++++++++++++--- crates/ui-egui/src/prefs_dialog/model.rs | 44 +++++++----- crates/ui-egui/src/prefs_dialog/tests.rs | 90 ++++++++++++++++++++++++ docs/mcp.md | 6 +- docs/target-app-parity.md | 1 + 6 files changed, 182 insertions(+), 28 deletions(-) diff --git a/crates/ui-egui/src/original_editor.rs b/crates/ui-egui/src/original_editor.rs index f9b8f00543..da3bf5d5ed 100644 --- a/crates/ui-egui/src/original_editor.rs +++ b/crates/ui-egui/src/original_editor.rs @@ -14,7 +14,7 @@ use crate::VectorcraftApp; /// Opaque saved choice. Public so hosts can construct `UiState` with a struct update; its path /// has no public setter and is never read from the generic preference or dialog-field maps. -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct Choice { path: Option, } @@ -45,8 +45,11 @@ pub(crate) fn open(app: &mut VectorcraftApp) { app.original_editor.choice = app.ui.original_editor.clone(); } -pub(crate) fn commit(app: &mut VectorcraftApp) { +/// Saves the dialog's choice; returns whether it differs from the saved one. +pub(crate) fn commit(app: &mut VectorcraftApp) -> bool { + let changed = app.ui.original_editor != app.original_editor.choice; app.ui.original_editor = app.original_editor.choice.clone(); + changed } pub(crate) fn reset(app: &mut VectorcraftApp) { diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs index cc1a102f26..c6cbd37e50 100644 --- a/crates/ui-egui/src/prefs_dialog.rs +++ b/crates/ui-egui/src/prefs_dialog.rs @@ -1,6 +1,6 @@ //! Edit → Preferences (⌘K): the framework's Preferences window over the engine's preference table //! ([`PREF_SPECS`]). The window edits a draft ([`PrefsWindow::draft`]; one key per preference, so agents can -//! `ui.dialog.set` any of them) and OK applies it through `prefs.set`. Also: persistence of engine prefs inside +//! `ui.dialog.set` any of them) and OK applies the rows changed in it through `prefs.set`. Also: persistence of engine prefs inside //! `UiState` and the per-frame application of the UI-side preferences ([`runtime`]). // PLAN: assumed import paths of the framework items below through the `craft_ui` facade (it re-exports the dialog @@ -44,9 +44,17 @@ pub struct PrefsWindow { draft: SettingsDraft, /// The draft as it was when the window opened or last applied: Apply is enabled while the draft differs. opened: SettingsDraft, + /// Each row's value as the window last read it from the preferences, the document or the UI state. OK and Apply + /// write only the rows whose draft value differs from it ([`Self::edited`]), so a setting changed outside the + /// window while it is open keeps its new value. + source: SettingsDraft, /// The Units ▸ General value Reset Preferences put in the draft, while it is still the row's value: OK then /// leaves the open document's units alone. reset_units: Option, + /// The rows set in the window (by the user, `ui.dialog.set` or a reset) since it last read them. OK writes them + /// even when they hold the value they were read with: a reset of a row a command changed while the window is + /// open, or of Units ▸ General, which shows the document's units, is still written. + touched: std::collections::BTreeSet, /// The colour picker and the Reset question, drawn in the window's own viewport. nested: DialogHost, reset_asked: Option, @@ -70,11 +78,39 @@ impl PrefsWindow { if key == "unitsGeneral" && self.reset_units.as_ref().is_some_and(|u| value.as_str() != Some(u)) { self.reset_units = None; } - self.draft.set(key, value); + self.set_row(key, value); self.sync_strings(); Ok(()) } + /// Whether the row `key` was changed in the window since it was last read: it was set there + /// ([`Self::touched`]), or its draft value differs from [`Self::source`]. Numbers compare by value, so `4` and + /// `4.0` are the same. + fn edited(&self, key: &str) -> bool { + if self.touched.contains(key) { + return true; + } + let (now, read) = (self.draft.get::(key), self.source.get::(key)); + match (now.as_ref().and_then(Value::as_f64), read.as_ref().and_then(Value::as_f64)) { + (Some(a), Some(b)) => a != b, + _ => now != read, + } + } + + /// Writes `value` at `key` in the draft and in [`Self::source`]: the row shows a value read from outside the + /// window, and OK does not write it back. + fn read(&mut self, key: &str, value: &Value) { + self.draft.set(key, value); + self.source.set(key, value); + self.touched.remove(key); + } + + /// 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); + self.touched.insert(key.to_string()); + } + /// Reads the draft's text and choice values again, after any write to the draft. fn sync_strings(&mut self) { use vectorcraft_engine::cmd::prefscmds::{PREF_SPECS, PrefKind}; @@ -90,7 +126,7 @@ impl PrefsWindow { fn refresh(&mut self, prefs: &Value) { for (k, v) in prefs.as_object().into_iter().flatten() { if self.draft.get::(k).is_some() { - self.draft.set(k, v); + self.read(k, v); } } self.reset_units = self.draft.get::("unitsGeneral"); @@ -102,7 +138,7 @@ impl PrefsWindow { let defaults = Prefs::default().to_json(); for key in keys { if let Some(v) = defaults.get(key) { - self.draft.set(key, v); + self.set_row(key, v); } } if self.draft.get::("unitsGeneral").is_some() { @@ -117,7 +153,9 @@ fn is_known(key: &str) -> bool { UI_FIELDS.iter().any(|f| f.0 == key) || spec(key).is_some() || PREF_GROUPS.contains(&key) } -/// Opens the window on `category` (matched ignoring case; General when it names none). +/// Opens the window on `category` (matched ignoring case; General when it names none). OK writes only the rows +/// changed in the window: a setting changed some other way while it is open (a command, a panel menu, a script) +/// keeps its new value. pub fn open(app: &mut VectorcraftApp, category: Option<&str>) { crate::original_editor::open(app); let mut draft = SettingsDraft::default(); @@ -126,7 +164,8 @@ pub fn open(app: &mut VectorcraftApp, category: Option<&str>) { fields.retain(|k, _| is_known(k)); // A restored settings file can hold a Hold Shortcut Delay outside its range: the window shows, // and OK sets, the delay in use. - if fields.contains_key("keyHoldDelay") { + let saved_delay = fields.get("keyHoldDelay").cloned(); + if saved_delay.is_some() { fields.insert("keyHoldDelay".into(), json!(app.session.prefs.key_hold_delay())); } // Units ▸ General shows (and OK sets) the open document's units. @@ -140,11 +179,18 @@ pub fn open(app: &mut VectorcraftApp, category: Option<&str>) { draft.set("__snapToGrid", &app.ui.view.snap_to_grid); draft.set("__taskBar", &app.ui.task_bar); let selected = category.and_then(|c| PREF_CATEGORIES.iter().find(|x| x.eq_ignore_ascii_case(c))).copied().unwrap_or(PREF_CATEGORIES[0]); + // The saved delay, so OK writes the delay in use in its place. + let mut source = draft.clone(); + if let Some(saved) = &saved_delay { + source.set("keyHoldDelay", saved); + } let mut w = PrefsWindow { state: PreferencesState::default(), opened: draft.clone(), + source, draft, reset_units: None, + touched: Default::default(), nested: DialogHost::new(), reset_asked: None, strings: Default::default(), @@ -362,7 +408,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.draft.set(key, &value); + w.read(key, &json!(value)); } } // And the reset preferences, the groups with a reset of every category; Units ▸ General then leaves the open @@ -373,7 +419,7 @@ 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.draft.set(k, v); + w.read(k, v); if k == "unitsGeneral" { w.reset_units = v.as_str().map(str::to_string); } diff --git a/crates/ui-egui/src/prefs_dialog/model.rs b/crates/ui-egui/src/prefs_dialog/model.rs index 0d03652289..b1e9bed4e9 100644 --- a/crates/ui-egui/src/prefs_dialog/model.rs +++ b/crates/ui-egui/src/prefs_dialog/model.rs @@ -283,7 +283,7 @@ impl Live<'_> { fn reset_ui_rows(&mut self, reset: impl Fn(&str) -> bool) { for (key, value) in super::default_ui_fields(&self.app.ui) { if UI_FIELDS.iter().any(|&(k, c, _)| k == key && reset(c)) { - self.w.draft.set(key, &value); + self.w.set_row(key, &json!(value)); } } } @@ -424,34 +424,44 @@ impl PreferencesDraft for Live<'_> { fn apply(&mut self) -> Result<(), String> { // 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)); - let values: Map = - self.w.draft.to::>().unwrap_or_default().into_iter().filter(|(k, _)| !k.starts_with("__")).collect(); + // 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 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)); // A refused folder, typed or picked, comes back here as the engine's message. - self.app.run("prefs.set", json!({ "values": values, "documentUnits": document_units }))?; + if !values.is_empty() { + self.app.run("prefs.set", json!({ "values": values, "documentUnits": document_units }))?; + } + let row = |key: &str| edited.get(key).and_then(Value::as_bool); // When OK enters the Touch workspace, the task bar is set before the switch, so it goes to the workspace being // left; otherwise after it, so a return from Touch gives it to the workspace returned to. let before_switch = touch_ws.is_some() && crate::workspaces::enters_touch(self.app, self.app.touch_screen); - if before_switch && let Some(on) = self.w.draft.get::("__taskBar") { + if before_switch && let Some(on) = row("__taskBar") { self.app.ui.task_bar = on; } if touch_ws.is_some() { crate::workspaces::sync_touch_workspace(self.app, self.app.touch_screen); } - let flag = |key: &str, now: bool| self.w.draft.get::(key).unwrap_or(now); - let (smart_guides, snap_to_grid, task_bar) = ( - flag("__smartGuides", self.app.ui.view.smart_guides), - flag("__snapToGrid", self.app.ui.view.snap_to_grid), - if before_switch { self.app.ui.task_bar } else { flag("__taskBar", self.app.ui.task_bar) }, - ); - self.app.ui.view.smart_guides = smart_guides; - self.app.ui.view.snap_to_grid = snap_to_grid; - self.app.ui.task_bar = task_bar; - crate::original_editor::commit(self.app); - super::snapshot(self.app); - self.app.prefs_changed = true; + if let Some(on) = row("__smartGuides") { + self.app.ui.view.smart_guides = on; + } + if let Some(on) = row("__snapToGrid") { + self.app.ui.view.snap_to_grid = on; + } + if !before_switch && let Some(on) = row("__taskBar") { + self.app.ui.task_bar = on; + } + let editor = crate::original_editor::commit(self.app); + // The host saves the settings only when one changed. + if !edited.is_empty() || editor { + super::snapshot(self.app); + self.app.prefs_changed = true; + } self.w.opened = self.w.draft.clone(); + self.w.source = self.w.draft.clone(); + self.w.touched.clear(); Ok(()) } diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 1b09df5cb0..bf1e2d093e 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -296,6 +296,18 @@ fn reset_preferences_keeps_an_edit_of_general_units() { reset_preferences(&mut b, PromptChoice::Proceed); confirm(&mut b).unwrap(); assert_eq!(b.session.prefs.units_general, Prefs::default().units_general); + + // A document in the default unit, with another unit saved: the row opens showing the default, and the reset + // still resets the saved unit. + let mut c = app(); + c.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + c.run("prefs.set", json!({"values": {"unitsGeneral": "inches"}, "documentUnits": false})).unwrap(); + assert_eq!(c.session.active().unwrap().doc.units.key(), Prefs::default().units_general); + open(&mut c, Some("General")); + reset_preferences(&mut c, PromptChoice::Proceed); + confirm(&mut c).unwrap(); + assert_eq!(c.session.prefs.units_general, Prefs::default().units_general, "the saved unit is reset"); + assert_eq!(c.session.active().unwrap().doc.units.key(), Prefs::default().units_general, "the document's units stay"); } /// Smart Guides, Snap to Grid and Enable Contextual Task Bar, the UI-only rows. @@ -538,6 +550,84 @@ fn prefs_reset_outside_run_resets_the_ui_only_rows_in_the_next_frame() { assert!(!left_task_bar(&b, "Essentials Classic"), "the workspace left keeps the reset value"); } +/// OK writes only the rows changed in Preferences: a preference, a UI-only row or the document's units changed by a +/// command while the window is open keeps its new value, and a row changed in the window is still written. +#[test] +fn ok_keeps_settings_changed_by_commands_while_preferences_is_open() { + let mut a = app(); + a.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + let before = ui_rows(&a); + open(&mut a, Some("General")); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 9})).unwrap(); + a.run("document.setUnits", json!({"units": "Millimeters"})).unwrap(); + for id in ["view.smartGuides", "view.snapToGrid", "window.taskBar"] { + a.run(id, json!({})).unwrap(); + } + set_field(&mut a, "constrainAngle", json!(30.0)).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.keyboard_increment, 9.0, "the command's preference"); + assert_eq!(a.session.active().unwrap().doc.units, vectorcraft_doc::Unit::Millimeters, "the command's units"); + assert_eq!(ui_rows(&a), (!before.0, !before.1, !before.2), "the commands' UI-only rows"); + assert_eq!(a.session.prefs.constrain_angle, 30.0, "the row changed in the window"); + assert_eq!(a.ui.engine_prefs["keyboardIncrement"], json!(9.0), "saved with the UI state"); + + // A row changed both ways takes the window's value; Cancel writes nothing. + open(&mut a, Some("General")); + set_field(&mut a, "keyboardIncrement", json!(3)).unwrap(); + set_field(&mut a, "constrainAngle", json!(15.0)).unwrap(); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 5})).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.keyboard_increment, 3.0, "the window's value"); + open(&mut a, Some("General")); + set_field(&mut a, "constrainAngle", json!(45.0)).unwrap(); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 6})).unwrap(); + cancel(&mut a); + assert_eq!((a.session.prefs.keyboard_increment, a.session.prefs.constrain_angle), (6.0, 15.0), "Cancel writes nothing"); + + // A reset in the window is written even where the row already showed the default: a command changed the + // preference after the window opened. + let default = Prefs::default().keyboard_increment; + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": default})).unwrap(); + open(&mut a, Some("General")); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 8})).unwrap(); + reset_preferences(&mut a, PromptChoice::Proceed); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.keyboard_increment, default, "the reset is written"); +} + +/// OK with nothing changed in Preferences writes nothing: no preference, no undo step in the document and no save +/// of the settings. +#[test] +fn ok_with_nothing_changed_writes_nothing() { + let mut a = app(); + a.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + let undo = a.session.active().unwrap().history.undo.len(); + let prefs = a.session.prefs.clone(); + a.take_prefs_changed(); + open(&mut a, Some("Units")); + confirm(&mut a).unwrap(); + assert!(!is_open(&a)); + assert_eq!(a.session.prefs, prefs); + assert_eq!(a.session.active().unwrap().history.undo.len(), undo, "no undo step"); + assert!(!a.take_prefs_changed(), "the settings are not saved again"); +} + +/// Enable Contextual Task Bar left alone in Preferences stays with each workspace: a workspace switch while the +/// window is open keeps the bar of the workspace switched to, and the workspace left keeps its own. +#[test] +fn ok_after_a_workspace_switch_keeps_each_workspaces_task_bar() { + let off = crate::workspaces::builtins().into_iter().find(|w| !w.record.task_bar).expect("a workspace saved with the bar off"); + let mut a = app(); + crate::workspaces::switch(&mut a, crate::workspaces::ESSENTIALS).unwrap(); + assert!(a.ui.task_bar, "Essentials starts with the bar on"); + open(&mut a, Some("General")); + a.run("window.workspace", json!({"name": off.name})).unwrap(); + set_field(&mut a, "keyboardIncrement", json!(3)).unwrap(); + confirm(&mut a).unwrap(); + assert!(!a.ui.task_bar, "{} keeps its bar off", off.name); + assert!(left_task_bar(&a, crate::workspaces::ESSENTIALS), "Essentials keeps its bar on"); +} + #[test] fn old_pref_files_keep_their_brightness() { let mut a = app(); diff --git a/docs/mcp.md b/docs/mcp.md index 61663febe2..558c6d648a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9054,7 +9054,11 @@ highlighted until another category is shown) and clears `__search`. Cmd/Ctrl+F f field with text clears it, and Escape in the empty field closes the dialog. Its Reset Preferences button opens a `resetPreferences` question (fields `message`, `detail`) over Preferences: `ui.dialog.cancel` shows Preferences again as it was, and `ui.dialog.confirm` shows it again with every preference at its default value, applied by OK in -Preferences. `prefs.reset` resets the preferences at once, without the question. +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. ```json {"name":"run_command","arguments":{"command":"prefs.set","params":{"key":"unitsGeneral","value":"millimeters"}}} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 09c2f07001..48cf0aef8d 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -895,6 +895,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 › 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`. From d07ca8514cec3512133d5998b7702b8ac99ae71c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 19:24:38 -0800 Subject: [PATCH 2/3] 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] From c192dfbd768c28ffb4427301cdfa12c4abdefdcf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 10:51:29 -0800 Subject: [PATCH 3/3] 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`.