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 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-26 20:34:09 +01:00
1 parent edada7542f
commit 112af3d7af
5 files changed
+57 -4

No files matched your search

@@ -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]
+9 -1
View File
@@ -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();
}
@@ -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();
}
+5 -2
View File
@@ -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<Value, String> {
// 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()
@@ -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());