From 2f86011d142f0da098a8bfec93c9d5cfdd648816 Mon Sep 17 00:00:00 2001 From: dholzric Date: Tue, 1 Dec 2026 01:54:11 -0600 Subject: [PATCH] Zoom: keep Zoom Out mode across Reset All Tools (#18191) `reset_all` in `crates/ui-egui/src/tools/tool_reset.rs` replaced `app.ui.tool_options` with `ToolOptions::default()`, switching the Zoom tool back to Zoom In (`zoom_in = true`) when it was in Zoom Out mode, whereas Reset Tool already kept `zoom_in`. Carry `zoom_in` across `ToolOptions::default()` in `reset_all` while still resetting Scrubby Zoom and the other tools' options, update `kept_by_reset_tool`'s doc comment, and update the single old assertion in `patch_reset_tool_tests.rs`. Co-authored-by: Cursor --- crates/ui-egui/src/patch_reset_tool_tests.rs | 2 +- crates/ui-egui/src/tools/tool_reset.rs | 13 ++- .../tools/zoom_reset_all_keeps_mode_tests.rs | 107 ++++++++++++++++++ 3 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs diff --git a/crates/ui-egui/src/patch_reset_tool_tests.rs b/crates/ui-egui/src/patch_reset_tool_tests.rs index c1ca920ae7e..1f03eefa4e8 100644 --- a/crates/ui-egui/src/patch_reset_tool_tests.rs +++ b/crates/ui-egui/src/patch_reset_tool_tests.rs @@ -76,7 +76,7 @@ fn rows() -> Vec { assert!(o.zoom_scrubby, "Scrubby Zoom goes back to on"); }, after_reset_all: |o| { - assert!(o.zoom_in, "Reset All Tools gives Zoom In"); + assert!(!o.zoom_in, "Reset All Tools keeps Zoom Out"); assert!(o.zoom_scrubby); }, }, diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 4e9bf5a5bed..2eecaf339dd 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -106,11 +106,12 @@ fn reset_tool(app: &mut PhotocraftApp, tool: Tool) { } } -/// Reset All Tools: every option, the selection mode and every tool's brush. +/// Reset All Tools: every option except Zoom In/Out, the selection mode and every tool's brush. fn reset_all(app: &mut PhotocraftApp) { crate::frame_tool::clear(app); app.ui.frame_tool = Default::default(); - *app.ui.tool_options = ToolOptions::default(); + let zoom_in = app.ui.tool_options.zoom_in; + *app.ui.tool_options = ToolOptions { zoom_in, ..ToolOptions::default() }; app.ui.artboard_tool = Default::default(); app.ui.selection_mode = 0; reset_session_brush(app); @@ -134,8 +135,8 @@ fn reset_session_brush(app: &mut PhotocraftApp) { /// The fields of [`option_keys`] that Reset Tool leaves as they are, as the reference app does /// (Zoom Out, #12066; Patch Structure and Color, #12127; Content-Aware Move Mode, #12183). -/// They stay in [`option_keys`], so a tool preset still stores them, and Reset All Tools still -/// resets them (it starts from the defaults). +/// They stay in [`option_keys`], so a tool preset still stores them; Reset All Tools keeps +/// `zoom_in` (#18191) and still resets the rest (not measured for Reset All Tools). fn kept_by_reset_tool(tool: Tool) -> &'static [&'static str] { match tool { Tool::Zoom => &["zoom_in"], @@ -494,3 +495,7 @@ mod art_history_reset_keeps_pressure_tests; #[cfg(test)] #[path = "bg_eraser_reset_pressure_tests.rs"] mod bg_eraser_reset_pressure_tests; + +#[cfg(test)] +#[path = "zoom_reset_all_keeps_mode_tests.rs"] +mod zoom_reset_all_keeps_mode_tests; diff --git a/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs b/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs new file mode 100644 index 00000000000..e289833201f --- /dev/null +++ b/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs @@ -0,0 +1,107 @@ +//! #18191: Reset All Tools leaves the Zoom tool in Zoom Out mode when it was set, as Reset Tool +//! already does, while resetting Scrubby Zoom and the other tools' options. + +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::control::{ControlRequest, Reply, handle}; +use crate::state::{Tool, ToolOptions}; + +fn app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); + app.sync_views(); + app +} + +fn invoke(app: &mut PhotocraftApp, id: &str, params: Value) { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new("ui.menu.invoke", json!({"id": id, "params": params})); + handle(app, &ctx, &req); + app.sync_views(); +} + +fn answer_dialog(app: &mut PhotocraftApp, method: &str, dialog: &str) -> Value { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new(method, json!({"dialog": dialog})); + let out = match handle(app, &ctx, &req) { + Reply::Done(v) => v, + _ => panic!("{method}: expected an immediate reply"), + }; + app.sync_views(); + out +} + +#[test] +fn reset_all_tools_keeps_zoom_out_and_resets_scrubby_zoom() { + let mut app = app(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.zoom_scrubby = false; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + assert!(!app.ui.tool_options.zoom_in, "Zoom Out stays selected"); + assert!(app.ui.tool_options.zoom_scrubby, "Scrubby Zoom goes back to on"); + assert_eq!(app.ui.tool, Tool::Zoom, "Zoom stays the current tool"); +} + +#[test] +fn reset_all_tools_keeps_zoom_in_when_selected() { + let mut app = app(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = true; + app.ui.tool_options.zoom_scrubby = false; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + assert!(app.ui.tool_options.zoom_in); + assert!(app.ui.tool_options.zoom_scrubby); +} + +#[test] +fn reset_all_tools_confirmation_ok_keeps_zoom_out_and_cancel_changes_nothing() { + let mut app = app(); + let ctx = app.ctx().clone(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.zoom_scrubby = false; + app.ui.tool_options.feather = 14.0; + + let dialog = crate::menus::invoke(&mut app, &ctx, "tool.resetAll", json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); + assert_eq!(answer_dialog(&mut app, "ui.dialog.cancel", &dialog)["ok"], true); + assert!(!app.ui.tool_options.zoom_in); + assert!(!app.ui.tool_options.zoom_scrubby, "Cancel keeps Scrubby Zoom off"); + assert_eq!(app.ui.tool_options.feather, 14.0, "Cancel keeps other options"); + + let dialog = crate::menus::invoke(&mut app, &ctx, "tool.resetAll", json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); + assert_eq!(answer_dialog(&mut app, "ui.dialog.confirm", &dialog)["ok"], true); + assert!(!app.ui.tool_options.zoom_in, "OK keeps Zoom Out"); + assert!(app.ui.tool_options.zoom_scrubby, "OK resets Scrubby Zoom to on"); + assert_eq!(app.ui.tool_options.feather, ToolOptions::default().feather); + assert_eq!(app.ui.tool, Tool::Zoom); +} + +#[test] +fn reset_all_tools_still_resets_unmeasured_kept_options_and_other_tools() { + let mut app = app(); + app.ui.tool = Tool::Brush; + crate::paint_mouse::sync_tool_brush(&mut app); + app.run("tools.setBrush", json!({"brush": {"size": 45}})).unwrap(); + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.patch_structure = 7.0; + app.ui.tool_options.patch_color = 5.0; + app.ui.tool_options.cam_mode = "extend".into(); + app.ui.tool_options.move_auto_select = false; + app.ui.selection_mode = 2; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + let d = ToolOptions::default(); + assert!(!app.ui.tool_options.zoom_in, "Zoom Out stays across Reset All Tools even when another tool is active"); + assert_eq!((app.ui.tool_options.patch_structure, app.ui.tool_options.patch_color), (d.patch_structure, d.patch_color)); + assert_eq!(app.ui.tool_options.cam_mode, d.cam_mode); + assert_eq!(app.ui.tool_options.move_auto_select, d.move_auto_select); + assert_eq!(app.ui.selection_mode, 0); + assert_eq!(app.run("brush.get", json!({})).unwrap()["size"].as_f64().unwrap(), 13.0); +}