Merge #18496 into the merge queue batch

Reveal layers selected through automation (#18493)
This commit is contained in:
David Mann committed 2026-12-01 02:04:12 +01:00
commit 2851b2e114
3 files changed
+75

No files matched your search

+4
View File
@@ -171,9 +171,13 @@ fn execute_command(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRe
return run_waiting(app, wait, |app| {
// These bypass `menus::invoke`: a Type box drag in progress applies its box first.
crate::type_box_preview::end_drag(app);
let revealed = (id == "layer.select").then(|| crate::layer_reveal::mark(app));
let previous = std::mem::replace(&mut app.programmatic_playback, true);
let result = app.run(id, params);
app.programmatic_playback = previous;
if let Some(revealed) = revealed {
crate::layer_reveal::file(app, revealed);
}
result
});
}
@@ -0,0 +1,69 @@
use egui_kittest::Harness;
use photocraft_doc::LayerContent;
use photocraft_engine::Session;
use serde_json::{Value, json};
use crate::control::{ControlRequest, Reply};
use crate::layers_panel_nodes::{layer_id, row_drawn};
use crate::{PhotocraftApp, state::Tool};
#[test]
fn automation_reveals_the_new_active_layer_in_a_closed_group() {
let mut session = Session::new();
session.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
session.execute("layer.new.layer", json!({"name": "Child"})).unwrap();
session.execute("layer.groupLayers", json!({})).unwrap();
let group = session.active().unwrap().active_layer.unwrap();
session.execute("layer.setExpanded", json!({"layer": group.0, "expanded": false})).unwrap();
// Put the group below the visible rows, so revealing it must also scroll the panel.
for index in 0..40 {
session.execute("layer.new.layer", json!({"name": format!("Top {index}")})).unwrap();
}
let mut harness = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(|cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), session, crate::Services::default());
app.ui.tool = Tool::Move;
app.ui.tool_options.move_expand_group_on_click = false;
app
});
let ctx = harness.ctx.clone();
let (req, _rx) = ControlRequest::new("ui.set", json!({"dock": {"collapsed": ["color", "properties", "history", "navigator"]}}));
crate::control::handle(harness.state_mut(), &ctx, &req);
harness.run_steps(8);
let group_open = |app: &PhotocraftApp| {
let doc = &app.session.active().unwrap().doc;
matches!(&doc.layer(group).unwrap().content, LayerContent::Group(group) if group.expanded)
};
let execute = |app: &mut PhotocraftApp, command: &str, params: Value| {
let (req, _rx) = ControlRequest::new("engine.execute", json!({"command": command, "params": params}));
assert!(matches!(crate::control::handle(app, &ctx, &req), Reply::Done(reply) if reply["ok"] == true));
};
assert!(!group_open(harness.state()));
assert!(!row_drawn(&harness, "Child"));
let child = layer_id(harness.state(), "Child");
execute(harness.state_mut(), "layer.select", json!({"name": "Child"}));
assert_eq!(harness.state().session.active().unwrap().active_layer, Some(child));
harness.run_steps(8);
assert!(group_open(harness.state()), "automation opens the group even when canvas picks keep it closed");
assert!(row_drawn(&harness, "Child"), "the selected row is scrolled into view");
harness.state_mut().session.execute("layer.setExpanded", json!({"layer": group.0, "expanded": false})).unwrap();
harness.run_steps(3);
assert!(!row_drawn(&harness, "Child"));
execute(harness.state_mut(), "layer.select", json!({"name": "Child"}));
harness.run_steps(8);
assert!(!group_open(harness.state()), "selecting the already-active layer leaves its closed group alone");
assert!(!row_drawn(&harness, "Child"));
execute(harness.state_mut(), "layer.new.layer", json!({"name": "New sibling"}));
let sibling = layer_id(harness.state(), "New sibling");
let state = harness.state().session.active().unwrap();
assert_eq!(state.active_layer, Some(sibling));
assert!(state.doc.layer(group).unwrap().children().unwrap().iter().any(|layer| layer.id == sibling));
harness.run_steps(8);
assert!(!group_open(harness.state()), "creating a layer through automation keeps the group closed");
assert!(!row_drawn(&harness, "New sibling"));
}
+2
View File
@@ -971,6 +971,8 @@ mod move_history_names_tests;
#[cfg(test)]
mod move_shift_diagonal_tests;
#[cfg(test)]
mod layer_reveal_automation_tests;
#[cfg(test)]
mod layers_footer_tests;
#[cfg(test)]