856f865cf98d
transform_undo_tests.rs
//! Free Transform through the real canvas: Undo and Redo step through the box's own changes (each
//! drag one step) and never reach the document under the open box; and the
//! handles have a generous grab radius, so a press just off a corner scales instead of rotating.
use egui::{Key, Modifiers, PointerButton, Pos2, vec2};
use egui_kittest::Harness;
use serde_json::json;
use crate::PhotocraftApp;
use crate::app::framework::BuildApp as _;
use crate::state::Tool;
/// A 400 × 300 document with a 100 × 60 red rectangle on its own layer at (100, 100), the Move
/// tool active, at 100 %.
fn harness() -> Harness<'static, Box<PhotocraftApp>> {
harness_tool(Tool::Move)
}
/// The same document with a chosen tool selected (e.g. Hand, #2302).
fn harness_tool(tool: Tool) -> Harness<'static, Box<PhotocraftApp>> {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.run("layer.new.layer", json!({})).unwrap();
app.run("select.rect", json!({"x": 100, "y": 100, "width": 100, "height": 60})).unwrap();
app.run("edit.fill", json!({"color": "#ff0000"})).unwrap();
app.run("select.deselect", json!({})).unwrap();
app.sync_views();
app.ui.extras.rulers = false;
app.ui.tool = tool;
let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(vec2(1000.0, 700.0)).build_app(
|ui, app: &mut PhotocraftApp| {
egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
},
app,
);
h.run_steps(4);
let v = &mut h.state_mut().ui.views[0];
v.zoom = 1.0;
v.center = [200.0, 150.0];
v.clear_pending();
h.run_steps(2);
h
}
fn screen(h: &mut Harness<'static, Box<PhotocraftApp>>, p: [f64; 2]) -> Pos2 {
crate::canvas::testing::to_screen(h.state_mut(), p)
}
/// Press at document point `from`, drag to `to` in a few steps and release.
fn drag(h: &mut Harness<'static, Box<PhotocraftApp>>, from: [f64; 2], to: [f64; 2]) {
let (a, b) = (screen(h, from), screen(h, to));
h.event(egui::Event::PointerMoved(a));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: a, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
for k in 1..=6 {
h.event(egui::Event::PointerMoved(a + (b - a) * (k as f32 / 6.0)));
h.run_steps(1);
}
h.event(egui::Event::PointerButton { pos: b, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(3);
}
fn begin(h: &mut Harness<'static, Box<PhotocraftApp>>) {
let ctx = h.ctx.clone();
crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransform", json!({})).unwrap();
h.run_steps(2);
}
fn quad(h: &Harness<'static, Box<PhotocraftApp>>) -> [[f64; 2]; 4] {
h.state().ui.transform.as_ref().expect("transforming").session.quad().map(|p| [p.x, p.y])
}
fn history(h: &Harness<'static, Box<PhotocraftApp>>) -> usize {
h.state().session.active().unwrap().history.entries().len()
}
fn key(h: &mut Harness<'static, Box<PhotocraftApp>>, m: Modifiers, k: Key) {
h.key_press_modifiers(m, k);
h.run_steps(2);
}
fn close(a: [[f64; 2]; 4], b: [[f64; 2]; 4]) -> bool {
a.iter().flatten().zip(b.iter().flatten()).all(|(x, y)| (x - y).abs() < 1e-6)
}
#[test]
fn free_transform_starts_where_the_selected_pixels_were_moved() {
let mut h = harness();
h.state_mut().run("select.rect", json!({"x": 100, "y": 100, "width": 100, "height": 60})).unwrap();
drag(&mut h, [150.0, 130.0], [250.0, 180.0]);
assert_eq!(photocraft_engine::float_cmds::floating(h.state().session.active().unwrap()).unwrap().offset, (100, 50));
begin(&mut h);
assert_eq!(quad(&h), [[200.0, 150.0], [300.0, 150.0], [300.0, 210.0], [200.0, 210.0]]);
let st = h.state().session.active().unwrap();
assert!(photocraft_engine::float_cmds::floating(st).is_none());
assert_eq!(st.doc.selection.as_ref().unwrap().content_bounds(), photocraft_geom::Rect::new(200, 150, 300, 210));
}
/// Scale ×2, then down again, then ⌘Z: back to the ×2 box, not the fill before the transform.
#[test]
fn undo_steps_back_through_the_transform_not_the_document() {
let mut h = harness();
h.state_mut().run("actions.reset", json!({"confirm":true,"mode":"append"})).unwrap();
let steps = history(&h);
begin(&mut h);
let q0 = quad(&h);
assert!(close(q0, [[100.0, 100.0], [200.0, 100.0], [200.0, 160.0], [100.0, 160.0]]), "{q0:?}");
drag(&mut h, q0[2], [300.0, 220.0]);
let q1 = quad(&h);
assert!(!close(q1, q0), "the first drag scaled the box");
drag(&mut h, q1[2], [150.0, 130.0]);
let q2 = quad(&h);
assert!(!close(q2, q1), "the second drag scaled it again");
key(&mut h, Modifiers::COMMAND, Key::Z);
assert!(close(quad(&h), q1), "⌘Z undoes the second drag: {:?}", quad(&h));
key(&mut h, Modifiers::COMMAND, Key::Z);
assert!(close(quad(&h), q0), "⌘Z again undoes the first");
// Nothing left to undo in the session: the document under the box is left alone.
key(&mut h, Modifiers::COMMAND, Key::Z);
assert!(close(quad(&h), q0));
assert_eq!(history(&h), steps, "the fill is still there");
assert_eq!(width(&h), 100);
key(&mut h, Modifiers::COMMAND | Modifiers::SHIFT, Key::Z);
assert!(close(quad(&h), q1), "⇧⌘Z redoes the first drag");
// A new change drops the redo; ↩ commits the session as one document step.
key(&mut h, Modifiers::NONE, Key::ArrowRight);
key(&mut h, Modifiers::COMMAND | Modifiers::SHIFT, Key::Z);
assert!(close(quad(&h), q1.map(|p| [p[0] + 1.0, p[1]])), "nudged, nothing to redo: {:?}", quad(&h));
key(&mut h, Modifiers::COMMAND, Key::Z);
assert!(close(quad(&h), q1), "a nudge is a step too");
key(&mut h, Modifiers::NONE, Key::Enter);
assert!(h.state().ui.transform.is_none());
assert_eq!(history(&h), steps + 1);
assert_ne!(width(&h), 100);
// Outside the transform, ⌘Z is the document's Undo again.
key(&mut h, Modifiers::COMMAND, Key::Z);
assert_eq!(width(&h), 100, "the committed transform is undone");
assert_eq!(h.state().session.actions.list.sets().len(), 1);
key(&mut h, Modifiers::COMMAND, Key::Z);
assert!(h.state().session.actions.list.sets().is_empty(), "the preceding library edit is next");
}
/// `engine.execute` over the control channel (and MCP, which goes through it) as a programmatic
/// caller: the result's `ok` flag.
fn execute(h: &mut Harness<'static, Box<PhotocraftApp>>, command: &str) -> bool {
let ctx = h.ctx.clone();
let (req, _rx) = crate::control::ControlRequest::new("engine.execute", json!({"command": command}));
let crate::control::Reply::Done(reply) = crate::control::handle(h.state_mut(), &ctx, &req) else {
panic!("{command}: expected an immediate reply");
};
h.run_steps(2);
reply["ok"].as_bool().unwrap()
}
/// Undo and Redo sent over the control channel step through the open box like ⌘Z, never the
/// document under it, and Toggle Last State is refused until the transform ends.
#[test]
fn automation_undo_steps_through_the_transform() {
let mut h = harness();
let steps = history(&h);
begin(&mut h);
let q0 = quad(&h);
drag(&mut h, q0[2], [300.0, 220.0]);
let q1 = quad(&h);
assert!(execute(&mut h, "edit.undo"));
assert!(close(quad(&h), q0), "undid the drag: {:?}", quad(&h));
assert!(execute(&mut h, "edit.undo"), "nothing left in the session: a no-op");
assert!(close(quad(&h), q0));
assert_eq!(history(&h), steps, "the fill is still there");
assert_eq!(width(&h), 100);
assert!(execute(&mut h, "edit.redo"));
assert!(close(quad(&h), q1), "redid the drag");
assert!(!execute(&mut h, "edit.toggleLastState"), "refused while transforming");
assert!(close(quad(&h), q1));
assert_eq!(history(&h), steps);
// Once the transform ends, they reach the document again.
key(&mut h, Modifiers::NONE, Key::Escape);
assert!(h.state().ui.transform.is_none());
assert!(execute(&mut h, "edit.undo"));
assert_eq!(history(&h), steps - 1, "the fill is undone");
}
fn width(h: &Harness<'static, Box<PhotocraftApp>>) -> u32 {
let st = h.state().session.active().unwrap();
st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().content_bounds().width()
}
/// With the Hand, Zoom or (freehand) Lasso selected, a Free Transform drag on a handle resizes the box rather than
/// panning or zooming the view or drawing a selection: the open box's tool owns the pointer (#2302, #4799, #2153).
#[test]
fn the_sessions_tool_takes_the_drag_under_every_selected_tool() {
for tool in [Tool::Hand, Tool::Zoom, Tool::Lasso] {
let mut h = harness_tool(tool);
if tool == Tool::Lasso {
let outline = json!([[90, 90], [210, 90], [210, 170], [90, 170]]);
h.state_mut().run("select.lasso", json!({"points": outline})).unwrap();
}
begin(&mut h);
let q0 = quad(&h);
let (zoom0, center0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center);
let steps = history(&h);
drag(&mut h, q0[2], [300.0, 220.0]);
let q1 = quad(&h);
assert!(!close(q1, q0), "{tool:?}: the drag scaled the box, not the view: {q1:?}");
assert_eq!(h.state().ui.views[0].zoom, zoom0, "{tool:?}: the view did not zoom");
assert_eq!(h.state().ui.views[0].center, center0, "{tool:?}: the view did not move");
assert_eq!(history(&h), steps, "{tool:?}: the drag adds no document step");
key(&mut h, Modifiers::NONE, Key::Enter);
assert!(h.state().ui.transform.is_none(), "{tool:?}: the transform committed");
assert!(width(&h) > 150, "{tool:?}: the committed resize applied: {}", width(&h));
}
}
/// Holding Space (the temporary Hand, #249) still pans the view while a Free Transform box is open,
/// rather than resizing it (#2302 review): only the selected Hand yields to the box.
#[test]
fn holding_space_still_pans_while_transforming() {
let mut h = harness();
begin(&mut h);
let q0 = quad(&h);
let center0 = h.state().ui.views[0].center;
let space = |h: &mut Harness<'static, Box<PhotocraftApp>>, down: bool| {
h.event(egui::Event::Key { key: Key::Space, physical_key: None, pressed: down, repeat: false, modifiers: Modifiers::NONE });
h.run_steps(1);
};
space(&mut h, true);
drag(&mut h, q0[2], [300.0, 220.0]);
space(&mut h, false);
h.run_steps(2);
assert!(close(quad(&h), q0), "the space-drag did not touch the box: {:?}", quad(&h));
assert_ne!(h.state().ui.views[0].center, center0, "the view panned instead");
}
#[test]
fn transform_preview_stays_visible_while_panning() {
let mut h = harness();
begin(&mut h);
let texture = h
.state()
.transform_preview
.as_ref()
.unwrap()
.textures
.pick(&h.ctx, craft::imaging::ui::transform_preview::PreviewTextures::choose(1.0, 1.0, false), None)
.expect("the preview uploads its texels")
.0;
// The preview paints in the canvas's picture slot, a list shape holding the document and the preview.
fn shows(shape: &egui::epaint::Shape, texture: egui::TextureId) -> bool {
match shape {
egui::epaint::Shape::Vec(list) => list.iter().any(|shape| shows(shape, texture)),
egui::epaint::Shape::Mesh(mesh) => mesh.texture_id == texture,
_ => false,
}
}
let has_preview = |h: &Harness<'static, Box<PhotocraftApp>>| h.output().shapes.iter().any(|clipped| shows(&clipped.shape, texture));
assert!(has_preview(&h), "the transformed pixels are visible before panning");
let center0 = h.state().ui.views[0].center;
let from = screen(&mut h, [200.0, 160.0]);
let to = from + vec2(50.0, 40.0);
h.event(egui::Event::Key { key: Key::Space, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.run_steps(1);
h.event(egui::Event::PointerMoved(from));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
h.event(egui::Event::PointerMoved(to));
h.run_steps(1);
assert_ne!(h.state().ui.views[0].center, center0, "the held Hand panned the view");
assert!(has_preview(&h), "the transformed layer stays visible during the pan");
}
/// A transform started by dragging a Move-tool control: that first drag is undoable too.
#[test]
fn the_first_drag_from_the_move_tools_controls_undoes() {
let mut h = harness();
h.state_mut().ui.tool_options.move_show_transform = true;
h.run_steps(1);
drag(&mut h, [200.0, 160.0], [260.0, 196.0]);
assert!(!close(quad(&h), [[100.0, 100.0], [200.0, 100.0], [200.0, 160.0], [100.0, 160.0]]));
key(&mut h, Modifiers::COMMAND, Key::Z);
assert!(close(quad(&h), [[100.0, 100.0], [200.0, 100.0], [200.0, 160.0], [100.0, 160.0]]), "{:?}", quad(&h));
}
/// #3402's layer-switch case (#5297): selected pixels moved with the Move tool, then moved again
/// in the Free Transform box, land where the box left them when another layer is picked.
#[test]
fn picking_another_layer_applies_the_transform_of_moved_selected_pixels() {
let mut h = harness();
let layer = h.state().session.active().unwrap().active_layer.unwrap();
h.state_mut().run("select.rect", json!({"x": 100, "y": 100, "width": 100, "height": 60})).unwrap();
drag(&mut h, [150.0, 130.0], [250.0, 180.0]);
begin(&mut h);
// Away from the centre, where a press would take the reference point instead.
drag(&mut h, [220.0, 165.0], [240.0, 175.0]);
assert_eq!(quad(&h), [[220.0, 160.0], [320.0, 160.0], [320.0, 220.0], [220.0, 220.0]]);
let other = h.state().session.active().unwrap().doc.layers.iter().map(|l| l.id).find(|id| *id != layer).unwrap();
h.state_mut().run("layer.select", json!({"layer": other.0})).unwrap();
crate::transform_tool::end_if_left(h.state_mut());
h.run_steps(3);
assert!(h.state().ui.transform.is_none(), "picking another layer applies the transform");
let st = h.state().session.active().unwrap();
let landed = photocraft_geom::Rect::new(220, 160, 320, 220);
let (pixels, selection) = (st.doc.layer(layer).unwrap().surface().unwrap().content_bounds(), st.doc.selection.as_ref().map(|s| s.content_bounds()));
assert_eq!((pixels, selection), (landed, Some(landed)));
}
/// #5297 through the real canvas: ⌘T with a selection wider than the layer opens the box on the
/// selection, and dragging it moves the selected pixels and the selection together.
#[test]
fn free_transform_opens_on_the_selection_and_moves_it_with_the_pixels() {
let mut h = harness();
let layer = h.state().session.active().unwrap().active_layer.unwrap();
// The left 60 px of the red rectangle, and empty layer to its left, above and below.
h.state_mut().run("select.rect", json!({"x": 60, "y": 80, "width": 100, "height": 120})).unwrap();
begin(&mut h);
assert_eq!(quad(&h), [[60.0, 80.0], [160.0, 80.0], [160.0, 200.0], [60.0, 200.0]]);
drag(&mut h, [80.0, 100.0], [130.0, 130.0]);
assert_eq!(quad(&h), [[110.0, 110.0], [210.0, 110.0], [210.0, 230.0], [110.0, 230.0]]);
key(&mut h, Modifiers::NONE, Key::Enter);
assert!(h.state().ui.transform.is_none());
let st = h.state().session.active().unwrap();
assert_eq!(st.doc.selection.as_ref().unwrap().content_bounds(), photocraft_geom::Rect::new(110, 110, 210, 230));
// What stayed (160..200 × 100..160) and what moved (to 150..210 × 130..190).
assert_eq!(st.doc.layer(layer).unwrap().surface().unwrap().content_bounds(), photocraft_geom::Rect::new(150, 100, 210, 190));
}
/// The harness's red layer plus a blue 50 × 50 one at (250, 200), both selected (#3592).
fn two_selected(h: &mut Harness<'static, Box<PhotocraftApp>>) -> (u64, u64) {
let app = h.state_mut();
let red = app.session.active().unwrap().active_layer.unwrap().0;
app.run("layer.new.layer", json!({})).unwrap();
app.run("select.rect", json!({"x": 250, "y": 200, "width": 50, "height": 50})).unwrap();
app.run("edit.fill", json!({"color": "#0000ff"})).unwrap();
app.run("select.deselect", json!({})).unwrap();
let blue = app.session.active().unwrap().active_layer.unwrap().0;
app.run("layer.select", json!({"layer": red, "mode": "add"})).unwrap();
app.sync_views();
h.run_steps(2);
(red, blue)
}
fn bounds(h: &Harness<'static, Box<PhotocraftApp>>, id: u64) -> photocraft_geom::Rect {
let st = h.state().session.active().unwrap();
st.doc.layer(photocraft_doc::LayerId(id)).unwrap().surface().unwrap().content_bounds()
}
#[test]
fn free_transform_moves_every_selected_layer_in_one_step() {
let mut h = harness();
let (red, blue) = two_selected(&mut h);
let steps = history(&h);
begin(&mut h);
let t = h.state().ui.transform.clone().expect("transforming");
assert_eq!(t.layers.len(), 2, "both layers move: {:?}", t.layers);
assert!(close(t.quad_array(), [[100.0, 100.0], [300.0, 100.0], [300.0, 250.0], [100.0, 250.0]]), "one box around both: {:?}", t.quad_array());
// Scale the shared box by ½ about its top-left corner.
set_quad(&mut h, [[100.0, 100.0], [200.0, 100.0], [200.0, 175.0], [100.0, 175.0]]);
key(&mut h, Modifiers::NONE, Key::Enter);
assert!(h.state().ui.transform.is_none());
assert_eq!(history(&h), steps + 1, "one history step");
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(100, 100, 150, 130));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(175, 150, 200, 175));
// One Undo restores both.
key(&mut h, Modifiers::COMMAND, Key::Z);
assert_eq!(history(&h), steps);
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(100, 100, 200, 160));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(250, 200, 300, 250));
}
#[test]
fn cancelling_a_multi_layer_transform_leaves_every_layer() {
let mut h = harness();
let (red, blue) = two_selected(&mut h);
let steps = history(&h);
begin(&mut h);
key(&mut h, Modifiers::NONE, Key::ArrowRight);
key(&mut h, Modifiers::NONE, Key::ArrowDown);
assert!(close(quad(&h), [[101.0, 101.0], [301.0, 101.0], [301.0, 251.0], [101.0, 251.0]]), "{:?}", quad(&h));
key(&mut h, Modifiers::NONE, Key::Escape);
assert!(h.state().ui.transform.is_none());
assert_eq!(history(&h), steps);
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(100, 100, 200, 160));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(250, 200, 300, 250));
}
#[test]
fn a_single_selected_layer_keeps_its_own_box() {
let mut h = harness();
begin(&mut h);
let t = h.state().ui.transform.clone().expect("transforming");
assert!(t.layers.is_empty());
assert!(close(t.quad_array(), [[100.0, 100.0], [200.0, 100.0], [200.0, 160.0], [100.0, 160.0]]));
}
#[test]
fn a_locked_layer_in_the_selection_refuses_the_box() {
let mut h = harness();
let (_, blue) = two_selected(&mut h);
h.state_mut()
.session
.edit("lock", |doc, _| {
doc.layer_mut(photocraft_doc::LayerId(blue)).unwrap().locks.position = true;
Ok(())
})
.unwrap();
let ctx = h.ctx.clone();
assert!(crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransform", json!({})).is_err());
assert!(h.state().ui.transform.is_none());
}
/// Sets the open box's corners through the session, as a typed field would.
fn set_quad(h: &mut Harness<'static, Box<PhotocraftApp>>, quad: [[f64; 2]; 4]) {
h.state_mut().ui.transform.as_mut().expect("transforming").edit_box(|b| b.quad = quad.map(|[x, y]| (x, y).into()));
}
fn shift_x(q: [[f64; 2]; 4], dx: f64) -> [[f64; 2]; 4] {
q.map(|p| [p[0] + dx, p[1]])
}
#[test]
fn several_layers_grey_warp_but_not_rotate_and_flip() {
// As in the reference application: Edit › Transform › Warp and its split items are greyed
// with two pixel layers selected; Rotate and Flip turn both around the shared box.
let mut h = harness();
two_selected(&mut h);
for id in ["edit.transform.warp", "edit.transform.splitWarpCrosswise", "edit.transform.removeWarpSplit"] {
assert!(!crate::menus::is_enabled(h.state(), id), "{id}");
}
for id in ["edit.transform.flipHorizontal", "edit.transform.flipVertical", "edit.transform.rotate180", "edit.transform.rotate90Cw"] {
assert!(crate::menus::is_enabled(h.state(), id), "{id}");
}
}
#[test]
fn free_transform_a_copy_duplicates_every_selected_layer_and_moves_the_copies() {
let mut h = harness();
let (red, blue) = two_selected(&mut h);
let steps = history(&h);
let count = |h: &Harness<'static, Box<PhotocraftApp>>| h.state().session.active().unwrap().doc.walk().len();
let n = count(&h);
let ctx = h.ctx.clone();
crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransformCopy", json!({})).unwrap();
h.run_steps(2);
let t = h.state().ui.transform.clone().expect("transforming");
assert_eq!(t.layers.len(), 2, "both copies in the box");
assert!(!t.layers.contains(&red) && !t.layers.contains(&blue), "the copies move, not the originals");
assert_eq!(count(&h), n + 2);
set_quad(&mut h, shift_x(t.quad_array(), 20.0));
key(&mut h, Modifiers::NONE, Key::Enter);
assert_eq!(history(&h), steps + 1, "the copies and their transform are one step");
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(100, 100, 200, 160));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(250, 200, 300, 250));
assert_eq!(bounds(&h, t.layers[0]), photocraft_geom::Rect::new(120, 100, 220, 160));
assert_eq!(bounds(&h, t.layers[1]), photocraft_geom::Rect::new(270, 200, 320, 250));
key(&mut h, Modifiers::COMMAND, Key::Z);
assert_eq!((count(&h), history(&h)), (n, steps), "one Undo takes both copies back");
// Esc takes the copies back too, leaving nothing to redo.
crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransformCopy", json!({})).unwrap();
h.run_steps(2);
key(&mut h, Modifiers::NONE, Key::Escape);
assert_eq!((count(&h), history(&h)), (n, steps));
}
#[test]
fn flip_and_rotate_menu_items_turn_every_selected_layer_around_the_shared_box() {
let mut h = harness();
let (red, blue) = two_selected(&mut h);
let steps = history(&h);
let ctx = h.ctx.clone();
crate::menus::invoke(h.state_mut(), &ctx, "edit.transform.flipHorizontal", json!({})).unwrap();
h.run_steps(2);
assert_eq!(history(&h), steps + 1);
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(200, 100, 300, 160));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(100, 200, 150, 250));
key(&mut h, Modifiers::COMMAND, Key::Z);
crate::menus::invoke(h.state_mut(), &ctx, "edit.transform.rotate180", json!({})).unwrap();
h.run_steps(2);
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(200, 190, 300, 250));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(100, 100, 150, 150));
}
#[test]
fn several_layers_keep_the_selection_frame_and_move_the_selection_once() {
let mut h = harness();
let (red, blue) = two_selected(&mut h);
h.state_mut().run("select.rect", json!({"x": 60, "y": 80, "width": 280, "height": 220})).unwrap();
begin(&mut h);
assert_eq!(quad(&h), [[60.0, 80.0], [340.0, 80.0], [340.0, 300.0], [60.0, 300.0]]);
let q = quad(&h);
set_quad(&mut h, shift_x(q, 10.0));
key(&mut h, Modifiers::NONE, Key::Enter);
assert!(h.state().ui.transform.is_none());
assert_eq!(bounds(&h, red), photocraft_geom::Rect::new(110, 100, 210, 160));
assert_eq!(bounds(&h, blue), photocraft_geom::Rect::new(260, 200, 310, 250));
assert_eq!(h.state().session.active().unwrap().doc.selection.as_ref().unwrap().content_bounds(), photocraft_geom::Rect::new(70, 80, 350, 300));
}
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.