From 112af3d7af77bb273a4bd346c319bd6fb4bca093 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 26 Nov 2026 20:34:09 +0100 Subject: [PATCH] perf(ui): a view command runs only the regions that show the view (#15493) Zoom, fit, print size and rotate counted as command runs, so each ran every panel body in the next frame. The regions that show the view hold it in their versions already; while an action is recorded a view command still counts, since the Actions panel lists the step. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/chrome_settle_trials.rs | 12 ++++++++ crates/ui-egui/src/control.rs | 10 ++++++- crates/ui-egui/src/input/shortcut_dispatch.rs | 4 ++- crates/ui-egui/src/menus/invoke.rs | 7 +++-- crates/ui-egui/src/panels/region_versions.rs | 28 +++++++++++++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index 1ff2f936f9..83b4a8dd81 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -112,6 +112,18 @@ fn a_hover_over_the_canvas_replays_the_toolbar_footer() { } } +/// Zoom In from the menu runs no panel body that does not show the view: before, every command counted as a command +/// run, so a zoom ran every panel body in the next frame (#15493). +#[test] +fn a_zoom_runs_only_the_panels_that_show_the_view() { + let mut h = harness(); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "view.zoomIn", json!({})).unwrap(); + h.run_steps(1); + let bodies = (views_ran(&h, "region_versions::PanelBody<"), views(&h, "region_versions::PanelBody<", MemoRun::Replayed)); + assert!(bodies.0 <= 1 && bodies.1 >= 2, "only the Navigator's body may run, the others replay: {bodies:?}"); +} + /// The footer runs again when a colour it shows changes without a command (the Color panel's sliders, a Color Picker /// preview) and when the document goes into Quick Mask, so its chips and button never show a stale state. #[test] diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index a91ad8e044..1868302df4 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -102,7 +102,15 @@ const INPUT_OR_READ: &[&str] = &[ ]; pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest) -> Reply { - if !INPUT_OR_READ.contains(&req.method.as_str()) { + // A view command run by id (`engine.execute`, `ui.menu.invoke`) changes only what the view's regions hold in their + // versions. + let command = match req.method.as_str() { + "engine.execute" => req.params.get("command"), + "ui.menu.invoke" => req.params.get("id"), + _ => None, + }; + let view_only = command.and_then(serde_json::Value::as_str).is_some_and(|id| crate::panels::region_versions::changes_only_the_view(app, id)); + if !INPUT_OR_READ.contains(&req.method.as_str()) && !view_only { app.commands_run += 1; ctx.request_repaint(); } diff --git a/crates/ui-egui/src/input/shortcut_dispatch.rs b/crates/ui-egui/src/input/shortcut_dispatch.rs index 76ba9b36b8..dae91f2b55 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch.rs @@ -584,7 +584,9 @@ pub(crate) fn run_fired(app: &mut PhotocraftApp, ctx: &egui::Context, fired: &[F // Artboard, Slice and panel commands) change what a settled region shows without going through `invoke`. A key's // repeats change only what has a revision or a tool option (brush size, a nudge, a mode step), so a held key // doesn't run every region at the repeat rate. - if fired.iter().any(|f| f.target.is_none() && f.phase != FirePhase::Repeat) { + // A view command (the canvas runs it) changes only what the view's regions hold in their versions. + let counts = |f: &&Fired| bridge_of(&f.command).is_none_or(|(id, _)| !crate::panels::region_versions::changes_only_the_view(app, id)); + if fired.iter().filter(|f| f.target.is_none() && f.phase != FirePhase::Repeat).any(|f| counts(&f)) { app.commands_run += 1; ctx.request_repaint(); } diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 2d01f0df91..700af635cd 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -70,8 +70,11 @@ fn keeps_box_drag(id: &str) -> bool { /// Run a command id from any source (menu, shortcut, palette, automation). pub fn invoke(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: Value) -> Result { - // The regions that ran before it in this pass show its change in the next one. - app.commands_run += 1; + // The regions that ran before it in this pass show its change in the next one. A view command changes only what + // the view's regions hold in their versions. + if !crate::panels::region_versions::changes_only_the_view(app, id) { + app.commands_run += 1; + } ctx.request_repaint(); if app.automation_input && let Some(authorize) = app.services.automation_command.as_ref() diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 32277e9e96..31abdea38b 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -146,6 +146,15 @@ pub(crate) fn panel(app: &PhotocraftApp, id: &str) -> u64 { /// filter mask, the selected path; the Layers, Channels, Paths and Properties panels and the canvas set it without a /// command), the tool and the preferences (Preferences' Apply and OK and other writers change them through the engine /// or `prefs.edit`, not as a counted command: units, the language, toolbar slots). +/// Whether running command `id` leaves every settling region's version as it is: a view command (zoom, fit, print size, +/// rotate) changes only the canvas view, which every region that shows it holds in its version (the Navigator, the Info +/// panel and the options bar through [`view`], the status bar in its own props), so it need not count as a command run +/// and run every panel body in the next frame (#15493). While an action is recorded it counts: the Actions panel lists +/// the step it records. +pub(crate) fn changes_only_the_view(app: &PhotocraftApp, id: &str) -> bool { + crate::shortcut_dispatch::is_view_command(id) && app.session.recording.target.is_none() +} + fn version(app: &PhotocraftApp, extra: impl Hash) -> u64 { let mut hasher = std::collections::hash_map::DefaultHasher::new(); app.commands_run.hash(&mut hasher); @@ -329,6 +338,25 @@ mod tests { } /// The UI language moves the title bar's version (its menu titles). + /// A view command from a key or a menu changes only the view: it is no command run, so the panel bodies keep their + /// versions (#15493). While an action is recorded it is one, because the Actions panel lists the step. + #[test] + fn a_view_command_is_no_command_run_unless_an_action_is_recorded() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + let ctx = egui::Context::default(); + let before = (app.commands_run, panel(&app, "layers"), panel(&app, "history")); + let fired = crate::blend_keys::test_fired(craft::ui::canvas::ViewCommands::ZoomIn.into()); + crate::shortcut_dispatch::run_fired(&mut app, &ctx, &[fired]); + let _ = crate::menus::invoke(&mut app, &ctx, "view.fitOnScreen", serde_json::json!({})); + assert_eq!((app.commands_run, panel(&app, "layers"), panel(&app, "history")), before, "a zoom key and Fit on Screen run no panel"); + app.session.recording.target = Some((0, 0)); + let _ = crate::menus::invoke(&mut app, &ctx, "view.fitOnScreen", serde_json::json!({})); + assert_eq!(app.commands_run, before.0 + 1, "recorded, Fit on Screen is a command run"); + let fired = crate::blend_keys::test_fired(craft::ui::canvas::ViewCommands::ZoomIn.into()); + crate::shortcut_dispatch::run_fired(&mut app, &ctx, &[fired]); + assert_eq!(app.commands_run, before.0 + 2, "recorded, a zoom key is a command run"); + } + #[test] fn the_language_moves_the_title_bar() { let app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());