From 9562ed9b04d7a89d101e9456bafbbbc54b177ab4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 10:26:19 -0800 Subject: [PATCH 1/5] Preferences: Reset Preferences resets Smart Guides, Snap to Grid and the Contextual Task Bar The Preferences dialog shows Smart Guides, Snap to Grid and General's Enable Contextual Task Bar, but the app keeps them with the interface state, and Reset Preferences left them as they were. Confirming Reset Preferences now puts their defaults in the dialog with the other defaults: Smart Guides on, Snap to Grid off, and the task bar as the current workspace was saved. OK applies them and Cancel keeps the values in use. On a touch screen, where the reset turns Enable Touch Workspace back on, OK sets the task bar in the workspace it leaves, and the Touch workspace keeps its own. prefs.reset (the Command Palette's Reset Preferences), alone or as a command.batch step, resets them too, each only when it resets every category or the setting's own (Smart Guides, Guides & Grid, General). With every category or File Handling it also clears the app chosen for Edit Original, as the dialog's reset does. The engine records the categories it reset (Session::take_prefs_resets), and the app resets its own settings from them after each command, each frame, and before a touch screen switches to the Touch workspace. A category that is not a string is now an error instead of a reset of every category. --- crates/engine/src/cmd/prefscmds.rs | 22 ++- crates/engine/src/lib.rs | 2 + crates/engine/src/session/documents.rs | 1 + crates/engine/src/tests/prefs.rs | 18 +++ crates/ui-egui/src/app.rs | 2 + crates/ui-egui/src/app/commands.rs | 3 + crates/ui-egui/src/dialogs/confirm.rs | 2 +- crates/ui-egui/src/original_editor.rs | 30 ++++ crates/ui-egui/src/prefs_dialog.rs | 53 ++++++- crates/ui-egui/src/prefs_dialog/tests.rs | 170 +++++++++++++++++++++++ crates/ui-egui/src/workspaces.rs | 2 + docs/mcp.md | 6 + docs/target-app-parity.md | 1 + 13 files changed, 299 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/prefscmds.rs b/crates/engine/src/cmd/prefscmds.rs index 46cdee28a5..16c64db12c 100644 --- a/crates/engine/src/cmd/prefscmds.rs +++ b/crates/engine/src/cmd/prefscmds.rs @@ -707,6 +707,12 @@ impl Prefs { } impl Session { + /// Take the categories `prefs.reset` reset since the last call, each once, with `None` for a + /// reset of every category. A frontend resets the settings it keeps itself in them. + pub fn take_prefs_resets(&mut self) -> Vec> { + std::mem::take(&mut self.prefs_resets) + } + /// Replace the preferences and push the ones with engine-side consumers into open documents /// and the renderer (grid, history depth, render threads). pub fn apply_prefs(&mut self, mut p: Prefs) { @@ -814,7 +820,7 @@ pub fn specs() -> Vec { always, set ), - cmd!(query "prefs.reset", "Reset Preferences", [], None, "{category?} reset one category (or everything) to defaults", always, reset), + cmd!(query "prefs.reset", "Reset Preferences", [], None, "{category?: string} reset one category (or everything, with category left out or null) to defaults; an unknown category or one that is not a string is an error", always, reset), cmd!(query "prefs.list", "List Preferences", [], None, "{} → [{key, category, section, label, kind, value, …}] every preference; under automation read roots a folder preference's value outside them is null", always, list), cmd!( query "prefs.export", @@ -997,15 +1003,17 @@ fn set(s: &mut Session, p: &Value) -> Result { } fn reset(s: &mut Session, p: &Value) -> Result { - let cat = str_param(p, "category"); - if let Some(c) = cat - && !PREF_CATEGORIES.iter().any(|x| x.eq_ignore_ascii_case(c)) - { - return Err(bad("prefs.reset", format!("unknown category `{c}`"))); - } + let cat = text_param(p, "category", "prefs.reset")?; + let known = |c: &str| { + PREF_CATEGORIES.iter().copied().find(|x| x.eq_ignore_ascii_case(c)).ok_or_else(|| bad("prefs.reset", format!("unknown category `{c}`"))) + }; + let category = cat.map(known).transpose()?; let mut next = s.prefs.clone(); next.reset(cat); s.apply_prefs(next); + if !s.prefs_resets.contains(&category) { + s.prefs_resets.push(category); + } Ok(json!({ "prefs": shown_prefs(&s.prefs) })) } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 68067dc697..f786340107 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -118,6 +118,8 @@ pub struct Session { /// Set when a command that draws a shape was journaled outside saved steps /// ([`Session::take_shape_drawn`]). shape_drawn: bool, + /// The categories `prefs.reset` reset, `None` for every one ([`Session::take_prefs_resets`]). + prefs_resets: Vec>, /// Set when the active tool panicked (see [`guard`]); reported by the next tool event. tool_panic: Option, /// How many times switching or closing documents, or replacing the active one, has started the diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 1685adc40f..156cd59ea3 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -74,6 +74,7 @@ impl Session { depth: 0, replaying: false, shape_drawn: false, + prefs_resets: Vec::new(), tool_panic: None, tool_resets: 0, tool_set_since_reset: false, diff --git a/crates/engine/src/tests/prefs.rs b/crates/engine/src/tests/prefs.rs index 966e68dc60..0d5bdab829 100644 --- a/crates/engine/src/tests/prefs.rs +++ b/crates/engine/src/tests/prefs.rs @@ -216,6 +216,24 @@ fn reset_category_and_all() { assert!(s.execute("prefs.reset", &json!({"category": "Bogus"})).is_err()); } +/// `prefs.reset` records each category it reset once, `None` for every category, and a failed +/// reset records nothing. +#[test] +fn prefs_reset_records_the_categories_it_reset() { + let mut s = Session::new(); + assert!(s.take_prefs_resets().is_empty()); + s.execute("prefs.reset", &json!({"category": "general"})).unwrap(); + s.execute("prefs.reset", &json!({"category": "General"})).unwrap(); + assert_eq!(s.take_prefs_resets(), vec![Some("General")]); + assert!(s.take_prefs_resets().is_empty(), "taking clears the list"); + assert!(s.execute("prefs.reset", &json!({"category": "Bogus"})).is_err()); + assert!(s.execute("prefs.reset", &json!({"category": 5})).is_err()); + assert!(s.take_prefs_resets().is_empty(), "a failed reset records nothing"); + s.execute("prefs.reset", &json!({})).unwrap(); + s.execute("prefs.reset", &json!({"category": "Type"})).unwrap(); + assert_eq!(s.take_prefs_resets(), vec![None, Some("Type")]); +} + /// A rectangle made into a guide path; nothing is selected after. fn guide_path(s: &mut Session, x: f64) -> NodeId { let id = square(s, x, 0.0); diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index bba6a5d83d..8142b558a8 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -652,6 +652,8 @@ impl VectorcraftApp { // panel (Show on Shape Creation). panels::transform::show_on_shape_creation(self, &ctx); crate::toasts::show(self, &ctx); + // A `prefs.reset` run in this pass outside `Self::run`. + crate::prefs_dialog::apply_prefs_resets(self); // After every panel had its chance to draw in this pass. crate::panels::three_d::end_stale_drag(self, &ctx); if self.custom_titlebar { diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 042e8b37a5..e68f68c50b 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -75,6 +75,8 @@ impl VectorcraftApp { pub fn run(&mut self, id: &str, params: Value) -> Result { self.beacon.command(id); let touch_workspace = self.session.prefs.touch_workspace; + // A `prefs.reset` that ran straight on the session applies before this command can switch workspaces. + crate::prefs_dialog::apply_prefs_resets(self); // A file dialog it shows off the UI thread runs it again with the path picked. let result = if self.picks.is_entry_free() { let entry = picks::Entry::Command(id.to_string(), params.clone()); @@ -82,6 +84,7 @@ impl VectorcraftApp { } else { self.run_now(id, params) }; + crate::prefs_dialog::apply_prefs_resets(self); if id == "prefs.import" && result.is_ok() { crate::prefs_dialog::imported(self, touch_workspace); } diff --git a/crates/ui-egui/src/dialogs/confirm.rs b/crates/ui-egui/src/dialogs/confirm.rs index 756bf71255..2b0a26b832 100644 --- a/crates/ui-egui/src/dialogs/confirm.rs +++ b/crates/ui-egui/src/dialogs/confirm.rs @@ -129,7 +129,7 @@ pub(crate) fn ask_reset_prefs(app: &mut VectorcraftApp) { /// OK on [`ask_reset_prefs`]: Preferences again, its fields at their defaults. fn reset_prefs(app: &mut VectorcraftApp, d: &Dialog) -> Result { let mut prefs = super::parent(d).filter(|p| p.kind == "preferences").ok_or("the dialog it was opened over is no longer open")?; - crate::prefs_dialog::reset_fields(&mut prefs); + crate::prefs_dialog::reset_fields(&mut prefs, &app.ui); crate::original_editor::reset(app); app.ui.dialog = Some(prefs); Ok(Value::Null) diff --git a/crates/ui-egui/src/original_editor.rs b/crates/ui-egui/src/original_editor.rs index ebdfcc4233..0936dc634e 100644 --- a/crates/ui-egui/src/original_editor.rs +++ b/crates/ui-egui/src/original_editor.rs @@ -33,6 +33,12 @@ pub(crate) fn reset(app: &mut VectorcraftApp) { app.original_editor.generation = app.original_editor.generation.wrapping_add(1); } +/// `prefs.reset`: the saved choice goes back to the default, and the next Preferences shows it. +pub(crate) fn reset_saved(app: &mut VectorcraftApp) { + app.ui.original_editor = Choice::default(); + reset(app); +} + pub(crate) fn cancel(app: &mut VectorcraftApp) { open(app); } @@ -173,6 +179,30 @@ mod tests { assert!(app.ui.original_editor.path.is_none()); } + /// `prefs.reset` of every category or of File Handling, alone or as a batch step, resets the + /// saved choice; a reset of another category keeps it. + #[test] + fn prefs_reset_resets_the_saved_choice_with_file_handling() { + let mut app = app(); + let chosen = |app: &mut VectorcraftApp| { + prefs_dialog::open(app, Some("File Handling")); + choose(app, Some("/Apps/My Editor.app")).unwrap(); + prefs_dialog::confirm(app).unwrap(); + assert!(app.ui.original_editor.path.is_some()); + }; + chosen(&mut app); + app.run("prefs.reset", json!({"category": "General"})).unwrap(); + assert!(app.ui.original_editor.path.is_some(), "General keeps the choice"); + app.run("prefs.reset", json!({"category": "File Handling"})).unwrap(); + assert!(app.ui.original_editor.path.is_none(), "File Handling resets it"); + chosen(&mut app); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + app.run("command.batch", json!({"commands": [{"command": "prefs.reset", "params": {}}]})).unwrap(); + assert!(app.ui.original_editor.path.is_none(), "every category, as a batch step"); + prefs_dialog::open(&mut app, Some("File Handling")); + assert!(app.original_editor.choice.path.is_none(), "Preferences shows the default"); + } + #[test] fn original_editor_routing_and_errors() { let mut app = app(); diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs index f6bd364449..70d7bc5d5f 100644 --- a/crates/ui-egui/src/prefs_dialog.rs +++ b/crates/ui-egui/src/prefs_dialog.rs @@ -225,12 +225,21 @@ pub fn confirm(app: &mut VectorcraftApp) -> Result { let touch_ws = values.get("touchWorkspace").and_then(Value::as_bool); let document_units = d.fields.get(RESET_UNITS).is_none_or(|v| values.get("unitsGeneral") != Some(v)); app.run("prefs.set", json!({ "values": values, "documentUnits": document_units }))?; + // Outside an automatic Touch switch, the task bar is set before OK can enter the Touch + // workspace, so it goes to the workspace being left; during one, after OK leaves it. + let task_bar = d.fields.get("__taskBar").and_then(Value::as_bool); + let before_switch = app.ui.touch_workspace_restore.is_none(); + if before_switch && let Some(on) = task_bar { + app.ui.task_bar = on; + } if touch_ws.is_some() { crate::workspaces::sync_touch_workspace(app, app.touch_screen); } app.ui.view.smart_guides = d.fields.get("__smartGuides").and_then(Value::as_bool).unwrap_or(app.ui.view.smart_guides); app.ui.view.snap_to_grid = d.fields.get("__snapToGrid").and_then(Value::as_bool).unwrap_or(app.ui.view.snap_to_grid); - app.ui.task_bar = d.fields.get("__taskBar").and_then(Value::as_bool).unwrap_or(app.ui.task_bar); + if !before_switch && let Some(on) = task_bar { + app.ui.task_bar = on; + } crate::original_editor::commit(app); app.ui.dialog = None; app.ui.engine_prefs = app.session.prefs.to_json(); @@ -484,17 +493,51 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } /// Reset Preferences, once its question is confirmed: every preference in the Preferences dialog -/// `d` takes its default value. The category, the search and the UI-only rows stay as they were; -/// nothing is applied until OK, which leaves the open document's units alone unless Units › -/// General is changed after the reset. -pub(crate) fn reset_fields(d: &mut Dialog) { +/// `d` takes its default value, the UI-only rows ([`UI_FIELDS`]) included. The category and the +/// search stay as they were; nothing is applied until OK, which leaves the open document's units +/// alone unless Units › General is changed after the reset. +pub(crate) fn reset_fields(d: &mut Dialog, ui: &crate::UiState) { for (k, v) in Prefs::default().to_json().as_object().cloned().unwrap_or_default() { d.fields.insert(k, v); } + for (key, value) in default_ui_fields(ui) { + d.fields.insert(key.into(), json!(value)); + } // OK resets the Units ▸ General preference and leaves the open document's units alone. d.fields.insert(RESET_UNITS.into(), d.fields.get("unitsGeneral").cloned().unwrap_or(Value::Null)); } +/// The default of each UI-only row ([`UI_FIELDS`]), by key. Enable Contextual Task Bar takes the +/// value the current workspace was saved with, so a reset leaves the workspace as it was saved. +fn default_ui_fields(ui: &crate::UiState) -> [(&'static str, bool); 3] { + let first = crate::UiState::default(); + let task_bar = crate::workspaces::find_saved(ui, &ui.workspace).map_or(first.task_bar, |w| w.task_bar); + [("__smartGuides", first.view.smart_guides), ("__snapToGrid", first.view.snap_to_grid), ("__taskBar", task_bar)] +} + +/// After `prefs.reset`, alone or as a batch step, of every category or of one: the UI-only rows +/// ([`UI_FIELDS`]) and the Edit Original app of the categories it reset take their defaults too. +pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) { + let resets = app.session.take_prefs_resets(); + if resets.is_empty() { + return; + } + let in_reset = |category: &str| resets.iter().any(|r| r.is_none_or(|c| c == category)); + for (key, value) in default_ui_fields(&app.ui) { + let reset = UI_FIELDS.iter().any(|&(k, c, _)| k == key && in_reset(c)); + match key { + "__smartGuides" if reset => app.ui.view.smart_guides = value, + "__snapToGrid" if reset => app.ui.view.snap_to_grid = value, + "__taskBar" if reset => app.ui.task_bar = value, + _ => {} + } + } + // The Edit Original row shows the app's Edit Original choice. + if vectorcraft_engine::cmd::prefscmds::spec("editOriginalSystemDefaults").is_some_and(|s| in_reset(s.category)) { + crate::original_editor::reset_saved(app); + } +} + /// The height of the fields column under the category's name: the field list, the gap and the /// description line. const FIELDS_HEIGHT: f32 = 400.0; diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index c79ca22470..0074301e7d 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -495,6 +495,159 @@ fn reset_preferences_then_ok_leaves_the_documents_units() { assert_eq!(st.history.undo.len(), undo, "no undo step"); } +/// Reset Preferences returns every UI-only row (Smart Guides, Snap to Grid, Enable Contextual Task +/// Bar) to its default in the dialog, the value a new app shows. OK applies them; Cancel keeps the values in use. +#[test] +fn reset_preferences_resets_the_ui_only_rows() { + let mut fresh = app(); + open(&mut fresh, None); + let first = fresh.ui.dialog.take().unwrap().fields; + let rows = |a: &VectorcraftApp| (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar); + let default = rows(&fresh); + let changed = (!default.0, !default.1, !default.2); + let reset_changed = |a: &mut VectorcraftApp| { + (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar) = changed; + open(a, Some("General")); + for (key, _, _) in UI_FIELDS { + assert_ne!(a.ui.dialog.as_ref().unwrap().fields[*key], first[*key], "{key} starts changed"); + } + reset_preferences(a); + }; + let mut a = app(); + reset_changed(&mut a); + for (key, _, _) in UI_FIELDS { + assert_eq!(a.ui.dialog.as_ref().unwrap().fields[*key], first[*key], "{key} is at its default in the dialog"); + } + assert_eq!(rows(&a), changed, "nothing applied before OK"); + confirm(&mut a).unwrap(); + assert_eq!(rows(&a), default, "OK applies the defaults"); + + let mut b = app(); + reset_changed(&mut b); + crate::dialogs::cancel(&mut b); + assert!(b.ui.dialog.is_none()); + assert_eq!(rows(&b), changed, "Cancel keeps the values in use"); +} + +/// `prefs.reset` (the Command Palette's Reset Preferences) also returns the UI-only rows to their +/// defaults, as a batch step too; with a category, only that category's rows; with an +/// unknown or malformed category, none. +#[test] +fn prefs_reset_resets_the_ui_only_rows_of_its_category() { + let fresh = app(); + let rows = |a: &VectorcraftApp| (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar); + let default = rows(&fresh); + let mut a = app(); + a.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar) = (!default.0, !default.1, !default.2); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap(); + for bad in [json!("Nowhere"), json!(["General"]), json!(5)] { + assert!(a.run("prefs.reset", json!({"category": bad})).is_err(), "{bad}"); + assert_eq!(rows(&a), (!default.0, !default.1, !default.2), "{bad}: an unknown or malformed category resets nothing"); + assert_eq!(a.session.prefs.keyboard_increment, 7.0, "{bad}: the preferences are kept"); + } + a.run("prefs.reset", json!({"category": "general"})).unwrap(); + assert_eq!(rows(&a), (!default.0, !default.1, default.2), "General: Enable Contextual Task Bar only"); + a.run("command.batch", json!({"commands": [{"command": "prefs.reset", "params": {"category": "Guides & Grid"}}]})).unwrap(); + assert_eq!(rows(&a), (!default.0, default.1, default.2), "Guides & Grid, as a batch step: Snap to Grid only"); + a.run("prefs.reset", json!({"category": "Smart Guides"})).unwrap(); + assert_eq!(rows(&a), default, "Smart Guides: Smart Guides"); + (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar) = (!default.0, !default.1, !default.2); + a.run("prefs.reset", json!({})).unwrap(); + assert_eq!(rows(&a), default, "every category"); +} + +/// Reset Preferences and `prefs.reset` give Enable Contextual Task Bar the value the current +/// workspace was saved with, which for a workspace saved with the bar off differs from the default. +#[test] +fn reset_preferences_gives_the_task_bar_the_workspaces_value() { + let off = crate::workspaces::builtins().into_iter().find(|w| !w.task_bar).unwrap(); + let in_workspace = |a: &mut VectorcraftApp| { + crate::workspaces::switch(&mut a.ui, &off.name).unwrap(); + assert!(!a.ui.task_bar, "{} starts with the bar off", off.name); + a.ui.task_bar = true; + }; + let mut a = app(); + in_workspace(&mut a); + open(&mut a, Some("General")); + reset_preferences(&mut a); + assert_eq!(a.ui.dialog.as_ref().unwrap().fields["__taskBar"], json!(false), "the dialog shows the workspace's value"); + confirm(&mut a).unwrap(); + assert!(!a.ui.task_bar, "OK applies the workspace's value"); + + let mut b = app(); + in_workspace(&mut b); + b.run("prefs.reset", json!({"category": "General"})).unwrap(); + assert!(!b.ui.task_bar, "prefs.reset gives the workspace's value"); + let mut c = app(); + assert!(c.ui.task_bar, "the default workspace starts with the bar on"); + c.ui.task_bar = false; + c.run("prefs.reset", json!({})).unwrap(); + assert!(c.ui.task_bar, "the default workspace's value"); +} + +/// On a touch screen, OK after Reset Preferences turns Enable Touch Workspace back on: the reset task +/// bar goes to the workspace left, and Touch keeps its own. With Touch entered automatically while +/// Preferences was open, clearing Enable Touch Workspace gives the row to the workspace returned to. +#[test] +fn ok_sets_the_task_bar_in_the_workspace_outside_touch() { + let mut a = app(); + a.touch_screen = true; + a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap(); + crate::workspaces::switch(&mut a.ui, "Essentials Classic").unwrap(); + a.ui.task_bar = true; + open(&mut a, Some("General")); + reset_preferences(&mut a); + assert_eq!(a.ui.dialog.as_ref().unwrap().fields["touchWorkspace"], json!(true), "the reset turns it on"); + confirm(&mut a).unwrap(); + assert_eq!(a.ui.workspace, crate::workspaces::TOUCH); + assert!(a.ui.task_bar, "Touch keeps its own task bar"); + let classic = a.ui.workspace_changes.iter().find(|w| w.name == "Essentials Classic").unwrap(); + assert!(!classic.task_bar, "the workspace left takes the reset value"); + + let mut b = app(); + b.run("prefs.set", json!({"key": "touchWorkspace", "value": true})).unwrap(); + crate::workspaces::switch(&mut b.ui, "Essentials Classic").unwrap(); + open(&mut b, Some("General")); + b.touch_screen = true; + crate::workspaces::sync_touch_workspace(&mut b, true); + assert_eq!(b.ui.workspace, crate::workspaces::TOUCH); + b.ui.dialog.as_mut().unwrap().fields.insert("touchWorkspace".into(), json!(false)); + confirm(&mut b).unwrap(); + assert_eq!(b.ui.workspace, "Essentials Classic"); + assert!(!b.ui.task_bar, "the workspace returned to takes the row"); + let touch = b.ui.workspace_changes.iter().find(|w| w.name == crate::workspaces::TOUCH).unwrap(); + assert!(touch.task_bar, "Touch keeps its own task bar"); +} + +/// A `prefs.reset` run straight on the session, outside `VectorcraftApp::run`, resets the UI-only +/// rows by the end of the next frame. +#[test] +fn prefs_reset_outside_run_resets_the_ui_only_rows_in_the_next_frame() { + let mut a = app(); + let default = (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar); + (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar) = (!default.0, !default.1, !default.2); + a.session.execute("prefs.reset", &json!({})).unwrap(); + let ctx = egui::Context::default(); + let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), ..Default::default() }; + let mut out = ctx.run_ui(raw, |ui| { + a.logic(ui.ctx()); + a.ui(ui); + }); + out.textures_delta.clear(); + assert_eq!((a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar), default); + + // Before the next command switches workspaces: the workspace left keeps the reset value. + let mut b = app(); + crate::workspaces::switch(&mut b.ui, "Essentials Classic").unwrap(); + b.ui.task_bar = true; + b.session.execute("prefs.reset", &json!({"category": "General"})).unwrap(); + b.run("window.workspace", json!({"name": crate::workspaces::ESSENTIALS})).unwrap(); + assert!(b.ui.task_bar, "Essentials keeps its own task bar"); + let classic = b.ui.workspace_changes.iter().find(|w| w.name == "Essentials Classic").unwrap(); + assert!(!classic.task_bar, "the workspace left keeps the reset value"); +} + /// After Reset Preferences, choosing a General unit in the dialog still sets the document's units /// on OK, Points included once another unit was chosen in between. With no document open, Reset /// Preferences resets General to its default. @@ -1517,6 +1670,23 @@ fn prefs_import_of_touch_workspace_switches_the_workspace() { assert_eq!(a.ui.workspace, "Typography"); } +/// A `prefs.reset` run straight on the session, then a touch screen that switches to Touch: the +/// workspace left keeps the reset value. +#[test] +fn a_pending_prefs_reset_applies_before_a_touch_switch() { + let mut a = app(); + a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap(); + crate::workspaces::switch(&mut a.ui, "Essentials Classic").unwrap(); + a.ui.task_bar = true; + a.session.execute("prefs.reset", &json!({})).unwrap(); + assert!(a.session.prefs.touch_workspace, "the reset turns Enable Touch Workspace on"); + crate::workspaces::sync_touch_workspace(&mut a, true); + assert_eq!(a.ui.workspace, crate::workspaces::TOUCH); + assert!(a.ui.task_bar, "Touch keeps its own task bar"); + let classic = a.ui.workspace_changes.iter().find(|w| w.name == "Essentials Classic").unwrap(); + assert!(!classic.task_bar, "the workspace left keeps the reset value"); +} + /// File Handling › Data Recovery › Folder has a Choose… button where the host has a folder /// picker, and none where it has not (the web). #[test] diff --git a/crates/ui-egui/src/workspaces.rs b/crates/ui-egui/src/workspaces.rs index c409b6b71a..a1c7464866 100644 --- a/crates/ui-egui/src/workspaces.rs +++ b/crates/ui-egui/src/workspaces.rs @@ -175,6 +175,8 @@ pub fn builtins() -> Vec { /// restored if Touch was entered automatically. Each switch keeps the layout it leaves and brings /// back the one it returns to as it was left, as Window › Workspace does. pub fn sync_touch_workspace(app: &mut VectorcraftApp, touch_screen: bool) { + // A pending `prefs.reset` applies to the workspace it was run in. + crate::prefs_dialog::apply_prefs_resets(app); let auto = app.session.prefs.touch_workspace && touch_screen; if auto { if app.ui.workspace != TOUCH { diff --git a/docs/mcp.md b/docs/mcp.md index 3c577e0356..3cda5a8c0b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8831,6 +8831,12 @@ Preferences. `prefs.reset` resets the preferences at once, without the question. {"name":"run_command","arguments":{"command":"prefs.set","params":{"key":"unitsGeneral","value":"millimeters"}}} ``` +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). 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. + `prefs.export {path?}` writes the preferences as a JSON file, `{"format": "vectorcraft-preferences", "version": 1, "prefs": {…}}`, and replies `{path, count}`; without `path` it replies `{data, count}` with the file's text. The file holds every preference `prefs.list` lists and the `eyedropper`, `perspectiveWidget`, `pathfinder`, `glyphSnap` and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3da663c191..f605c84224 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -885,6 +885,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Preferences › User Interface › Open Documents As Tabs (G7, #394):** checked by default, documents open under tabs in one document window ([public source](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/workspace-overview.html)). With the box cleared, each document opened or created afterwards opens in a floating window of its own, at the next cascade place, as Float in Window floats it; documents already open stay where they are, and checking the box again leaves floating documents in their windows. Tests: `crates/ui-egui/src/doc_windows/tests.rs`. - **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. `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 › 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 3b0823e432f472ec186e49f2db356533e66cc148 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 21:05:59 -0800 Subject: [PATCH 2/5] Preferences: OK puts the reset task bar in the workspace it leaves OK now sets Enable Contextual Task Bar before the Touch switch only when that switch enters Touch, decided from the Enable Touch Workspace preference, the touch screen and the current workspace. A Touch return marker left from an earlier automatic switch no longer sends the value to Touch. A prefs.reset applied after the panels draw requests a repaint, so the next pass shows the reset rows. --- crates/ui-egui/src/app.rs | 6 ++++-- crates/ui-egui/src/prefs_dialog.rs | 13 ++++++++----- crates/ui-egui/src/prefs_dialog/tests.rs | 20 ++++++++++++++++++++ crates/ui-egui/src/workspaces.rs | 5 +++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 8142b558a8..663ce32b90 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -652,8 +652,10 @@ impl VectorcraftApp { // panel (Show on Shape Creation). panels::transform::show_on_shape_creation(self, &ctx); crate::toasts::show(self, &ctx); - // A `prefs.reset` run in this pass outside `Self::run`. - crate::prefs_dialog::apply_prefs_resets(self); + // A `prefs.reset` run in this pass outside `Self::run`; the next pass draws the reset rows. + if crate::prefs_dialog::apply_prefs_resets(self) { + ctx.request_repaint(); + } // After every panel had its chance to draw in this pass. crate::panels::three_d::end_stale_drag(self, &ctx); if self.custom_titlebar { diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs index 70d7bc5d5f..0f777a9dca 100644 --- a/crates/ui-egui/src/prefs_dialog.rs +++ b/crates/ui-egui/src/prefs_dialog.rs @@ -225,10 +225,11 @@ pub fn confirm(app: &mut VectorcraftApp) -> Result { let touch_ws = values.get("touchWorkspace").and_then(Value::as_bool); let document_units = d.fields.get(RESET_UNITS).is_none_or(|v| values.get("unitsGeneral") != Some(v)); app.run("prefs.set", json!({ "values": values, "documentUnits": document_units }))?; - // Outside an automatic Touch switch, the task bar is set before OK can enter the Touch - // workspace, so it goes to the workspace being left; during one, after OK leaves it. + // 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 task_bar = d.fields.get("__taskBar").and_then(Value::as_bool); - let before_switch = app.ui.touch_workspace_restore.is_none(); + let before_switch = touch_ws.is_some() && crate::workspaces::enters_touch(app, app.touch_screen); if before_switch && let Some(on) = task_bar { app.ui.task_bar = on; } @@ -517,10 +518,11 @@ fn default_ui_fields(ui: &crate::UiState) -> [(&'static str, bool); 3] { /// After `prefs.reset`, alone or as a batch step, of every category or of one: the UI-only rows /// ([`UI_FIELDS`]) and the Edit Original app of the categories it reset take their defaults too. -pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) { +/// Returns whether any reset was pending. +pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) -> bool { let resets = app.session.take_prefs_resets(); if resets.is_empty() { - return; + return false; } let in_reset = |category: &str| resets.iter().any(|r| r.is_none_or(|c| c == category)); for (key, value) in default_ui_fields(&app.ui) { @@ -536,6 +538,7 @@ pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) { if vectorcraft_engine::cmd::prefscmds::spec("editOriginalSystemDefaults").is_some_and(|s| in_reset(s.category)) { crate::original_editor::reset_saved(app); } + true } /// The height of the fields column under the category's name: the field list, the gap and the diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 0074301e7d..05720a2e26 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -620,6 +620,26 @@ fn ok_sets_the_task_bar_in_the_workspace_outside_touch() { assert!(touch.task_bar, "Touch keeps its own task bar"); } +/// A Touch return marker left over from an earlier automatic switch (Window › Workspace does not +/// clear it) does not change where OK puts the task bar: OK enters Touch from the workspace it +/// leaves, so that workspace takes the row and Touch keeps its own. +#[test] +fn ok_sets_the_task_bar_in_the_workspace_left_with_a_stale_touch_marker() { + let mut a = app(); + a.touch_screen = true; + a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap(); + a.ui.touch_workspace_restore = Some("Typography".into()); + crate::workspaces::switch(&mut a.ui, "Essentials Classic").unwrap(); + a.ui.task_bar = true; + open(&mut a, Some("General")); + reset_preferences(&mut a); + confirm(&mut a).unwrap(); + assert_eq!(a.ui.workspace, crate::workspaces::TOUCH); + assert!(a.ui.task_bar, "Touch keeps its own task bar"); + let classic = a.ui.workspace_changes.iter().find(|w| w.name == "Essentials Classic").unwrap(); + assert!(!classic.task_bar, "the workspace left takes the reset value"); +} + /// A `prefs.reset` run straight on the session, outside `VectorcraftApp::run`, resets the UI-only /// rows by the end of the next frame. #[test] diff --git a/crates/ui-egui/src/workspaces.rs b/crates/ui-egui/src/workspaces.rs index a1c7464866..a974d13358 100644 --- a/crates/ui-egui/src/workspaces.rs +++ b/crates/ui-egui/src/workspaces.rs @@ -170,6 +170,11 @@ pub fn builtins() -> Vec { ] } +/// Whether [`sync_touch_workspace`] with `touch_screen` switches to the Touch workspace. +pub fn enters_touch(app: &VectorcraftApp, touch_screen: bool) -> bool { + app.session.prefs.touch_workspace && touch_screen && app.ui.workspace != TOUCH +} + /// Preferences › Devices › Enable Touch Workspace (#394): on, a touch screen switches to the Touch /// workspace; off, or when no touch screen is reported, the workspace before that switch is /// restored if Touch was entered automatically. Each switch keeps the layout it leaves and brings From 99c37518d2ed601f2d60f5256be6ccb14a2d145c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 21:33:22 -0800 Subject: [PATCH 3/5] Preferences: prefs.reset with Preferences open keeps the reset on OK A prefs.reset run while the Preferences dialog is open now puts the reset values in the dialog: the UI-only rows and the preferences of the categories it reset, and the preference groups when it resets every category. OK applies a reset still pending from outside the command path before it reads the dialog. OK then applies the reset values instead of the dialog's earlier ones, and leaves the open document's units alone. --- crates/ui-egui/src/prefs_dialog.rs | 22 +++++++++++++ crates/ui-egui/src/prefs_dialog/tests.rs | 42 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs index 0f777a9dca..d3e0f9641d 100644 --- a/crates/ui-egui/src/prefs_dialog.rs +++ b/crates/ui-egui/src/prefs_dialog.rs @@ -220,6 +220,8 @@ pub(crate) fn note_set(d: &mut Dialog, field: &str, value: &Value) { /// OK: validate and apply every preference in the dialog (nothing changes on error). pub fn confirm(app: &mut VectorcraftApp) -> Result { + // A `prefs.reset` run since the last frame shows in the dialog before OK reads it. + apply_prefs_resets(app); let Some(d) = app.ui.dialog.clone() else { return Err("no dialog open".into()) }; let values: Map = d.fields.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); @@ -525,6 +527,7 @@ pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) -> bool { return false; } let in_reset = |category: &str| resets.iter().any(|r| r.is_none_or(|c| c == category)); + let prefs = app.session.prefs.to_json(); for (key, value) in default_ui_fields(&app.ui) { let reset = UI_FIELDS.iter().any(|&(k, c, _)| k == key && in_reset(c)); match key { @@ -533,6 +536,25 @@ pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) -> bool { "__taskBar" if reset => app.ui.task_bar = value, _ => {} } + // An open Preferences dialog shows the reset rows, so OK keeps them. + if reset && let Some(d) = app.ui.dialog.as_mut().filter(|d| d.kind == "preferences") { + d.fields.insert(key.into(), json!(value)); + } + } + // And the reset preferences, the groups with a reset of every category; Units › General then + // leaves the open document's units alone on OK. + use vectorcraft_engine::cmd::prefscmds::{PREF_GROUPS, spec}; + let every = resets.contains(&None); + if let Some(d) = app.ui.dialog.as_mut().filter(|d| d.kind == "preferences") { + 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 d.fields.contains_key(k) && reset { + d.fields.insert(k.clone(), v.clone()); + if k == "unitsGeneral" { + d.fields.insert(RESET_UNITS.into(), v.clone()); + } + } + } } // The Edit Original row shows the app's Edit Original choice. if vectorcraft_engine::cmd::prefscmds::spec("editOriginalSystemDefaults").is_some_and(|s| in_reset(s.category)) { diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 05720a2e26..d3838a574f 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -557,6 +557,48 @@ fn prefs_reset_resets_the_ui_only_rows_of_its_category() { assert_eq!(rows(&a), default, "every category"); } +/// A `prefs.reset` run while Preferences is open shows the reset values in the dialog, for the +/// categories it reset, so OK keeps the reset; rows of other categories keep the dialog's values. +#[test] +fn prefs_reset_while_preferences_is_open_shows_the_reset_values() { + let fresh = app(); + let rows = |a: &VectorcraftApp| (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar); + let default = rows(&fresh); + let mut a = app(); + (a.ui.view.smart_guides, a.ui.view.snap_to_grid, a.ui.task_bar) = (!default.0, !default.1, !default.2); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap(); + open(&mut a, Some("General")); + a.run("prefs.reset", json!({"category": "General"})).unwrap(); + let d = a.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["__taskBar"], json!(default.2), "the dialog shows the reset row"); + assert_eq!(d.fields["__smartGuides"], json!(!default.0), "a row of another category keeps its value"); + confirm(&mut a).unwrap(); + assert_eq!(rows(&a), (!default.0, !default.1, default.2), "OK keeps the reset"); + assert_eq!(a.session.prefs.keyboard_increment, fresh.session.prefs.keyboard_increment, "OK keeps the reset preference"); + + // Every category, the preference groups included. + let group = fresh.session.prefs.to_json()["pixelSnap"].clone(); + let mut changed = group.clone(); + let flag = changed.as_object_mut().and_then(|o| o.values_mut().find(|v| v.is_boolean())).expect("a pixelSnap option is a boolean"); + *flag = json!(!flag.as_bool().unwrap_or_default()); + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap(); + a.run("prefs.set", json!({"key": "pixelSnap", "value": changed})).unwrap(); + open(&mut a, Some("General")); + assert_eq!(a.ui.dialog.as_ref().unwrap().fields["pixelSnap"], changed); + a.run("prefs.reset", json!({})).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(rows(&a), default, "every category"); + assert_eq!(a.session.prefs.keyboard_increment, fresh.session.prefs.keyboard_increment); + assert_eq!(a.session.prefs.to_json()["pixelSnap"], group, "OK keeps the reset group"); + + // Run straight on the session, with OK before the next frame. + a.run("prefs.set", json!({"key": "keyboardIncrement", "value": 7})).unwrap(); + open(&mut a, Some("General")); + a.session.execute("prefs.reset", &json!({"category": "General"})).unwrap(); + confirm(&mut a).unwrap(); + assert_eq!(a.session.prefs.keyboard_increment, fresh.session.prefs.keyboard_increment, "OK keeps a reset outside run"); +} + /// Reset Preferences and `prefs.reset` give Enable Contextual Task Bar the value the current /// workspace was saved with, which for a workspace saved with the bar off differs from the default. #[test] From 0f7844ecb6bdcf9e03056aef50d9a10136bd18d2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 18:22:36 -0800 Subject: [PATCH 4/5] Preferences: Apply after entering Touch keeps Touch's task bar After an Apply that entered Touch, the Enable Contextual Task Bar row kept the value given to the workspace left, and the next Apply wrote it to Touch. The row now shows the task bar in use after each Apply. When OK leaves Touch, the workspace returned to takes the row only when it was edited; otherwise it keeps the value it left with. --- crates/ui-egui/src/prefs_dialog/model.rs | 10 +++++- crates/ui-egui/src/prefs_dialog/tests.rs | 46 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/prefs_dialog/model.rs b/crates/ui-egui/src/prefs_dialog/model.rs index 0d03652289..25740a3dce 100644 --- a/crates/ui-egui/src/prefs_dialog/model.rs +++ b/crates/ui-egui/src/prefs_dialog/model.rs @@ -436,14 +436,19 @@ impl PreferencesDraft for Live<'_> { if before_switch && let Some(on) = self.w.draft.get::("__taskBar") { self.app.ui.task_bar = on; } + let was_touch = crate::workspaces::is_current(&self.app.ui, crate::workspaces::TOUCH); if touch_ws.is_some() { crate::workspaces::sync_touch_workspace(self.app, self.app.touch_screen); } + // When OK leaves Touch, the workspace returned to takes the row only when it changed since the window opened or + // last applied; otherwise it keeps its own. + let left_touch = was_touch && !crate::workspaces::is_current(&self.app.ui, crate::workspaces::TOUCH); + let task_bar_row = self.w.draft.get::("__taskBar").filter(|on| !left_touch || self.w.opened.get::("__taskBar") != Some(*on)); 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) }, + if before_switch { self.app.ui.task_bar } else { task_bar_row.unwrap_or(self.app.ui.task_bar) }, ); self.app.ui.view.smart_guides = smart_guides; self.app.ui.view.snap_to_grid = snap_to_grid; @@ -451,6 +456,9 @@ impl PreferencesDraft for Live<'_> { crate::original_editor::commit(self.app); super::snapshot(self.app); self.app.prefs_changed = true; + // 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. + self.w.draft.set("__taskBar", &self.app.ui.task_bar); self.w.opened = self.w.draft.clone(); Ok(()) } diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 1b09df5cb0..5930e2def0 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -495,6 +495,52 @@ fn ok_sets_the_task_bar_in_the_workspace_outside_touch() { assert!(left_task_bar(&b, TOUCH), "Touch keeps its own task bar"); } +/// After an Apply that enters Touch, the task bar row shows Touch's task bar: a later Apply that leaves the row +/// unedited keeps it, and an edit or a reset of the row reaches it. Leaving Touch with the row unedited gives the +/// workspace returned to the value it left with. +#[test] +fn apply_after_entering_touch_keeps_touchs_task_bar() { + use crate::workspaces::{TOUCH, is_current, switch}; + use craft::ui::patterns::preferences::PreferencesDraft as _; + let apply = |a: &mut VectorcraftApp| { + let mut w = a.prefs.take().expect("Preferences is open"); + let r = model::Live { app: &mut *a, w: &mut w }.apply(); + a.prefs = Some(w); + r.unwrap(); + }; + let mut a = app(); + a.touch_screen = true; + a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap(); + switch(&mut a, "Essentials Classic").unwrap(); + a.ui.task_bar = true; + open(&mut a, Some("General")); + reset_preferences(&mut a, PromptChoice::Proceed); + assert_eq!(field(&a, "__taskBar"), json!(false), "the reset row differs from Touch's task bar"); + apply(&mut a); + assert!(is_current(&a.ui, TOUCH)); + assert!(a.ui.task_bar, "Touch keeps its own task bar"); + set_field(&mut a, "keyboardIncrement", json!(9)).unwrap(); + apply(&mut a); + assert!(is_current(&a.ui, TOUCH)); + assert!(a.ui.task_bar, "an Apply without a task bar edit keeps Touch's task bar"); + assert_eq!(field(&a, "__taskBar"), json!(true), "the row shows Touch's task bar"); + set_field(&mut a, "__taskBar", json!(false)).unwrap(); + apply(&mut a); + assert!(!a.ui.task_bar, "an edit to the row reaches Touch"); + + // Reset Preferences in Touch gives Touch its saved value, the value the row showed before the edit. + reset_preferences(&mut a, PromptChoice::Proceed); + apply(&mut a); + assert!(is_current(&a.ui, TOUCH)); + assert!(a.ui.task_bar, "the reset reaches Touch"); + + // Leaving Touch with the row unedited: the workspace returned to keeps the value it left with. + set_field(&mut a, "touchWorkspace", json!(false)).unwrap(); + apply(&mut a); + assert!(is_current(&a.ui, "Essentials Classic")); + assert!(!a.ui.task_bar, "the workspace returned to keeps its reset value"); +} + /// A Touch return marker left over from an earlier automatic switch (Window › Workspace does not clear it) does not /// change where OK puts the task bar: OK enters Touch from the workspace it leaves, so that workspace takes the row /// and Touch keeps its own. From 924c4409bb0faf3a5b9a11d0a8381e4a0b9e87f9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 18:43:42 -0800 Subject: [PATCH 5/5] Preferences test: run the reset frame through testing::app_frame The test of a prefs.reset run outside VectorcraftApp::run now draws its frame with crate::testing::app_frame on the window's context. --- crates/ui-egui/src/prefs_dialog/tests.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 5930e2def0..daad8a6bef 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -569,9 +569,8 @@ fn prefs_reset_outside_run_resets_the_ui_only_rows_in_the_next_frame() { let default = ui_rows(&a); set_ui_rows(&mut a, (!default.0, !default.1, !default.2)); a.session.execute("prefs.reset", &json!({})).unwrap(); - let ctx = crate::testing::ui_context(); - let mut out = ctx.run_ui(egui::RawInput::default(), |ui| a.tick(ui.ctx())); - out.textures_delta.clear(); + let ctx = a.ui_ctx.clone().expect("a window context"); + crate::testing::app_frame(&mut a, &ctx, egui::RawInput::default()); assert_eq!(ui_rows(&a), default); // Before the next command switches workspaces: the workspace left keeps the reset value.