From 18897c8d0ea8df4e8d90c11fafae0f5981c0952b Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:32:21 +0100 Subject: [PATCH 1/2] Restore guide and selection outline paint-order coverage --- crates/ui-egui/src/canvas/tests.rs | 94 ++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index daf454eb5f..33e44212b5 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -659,6 +659,21 @@ fn a_secondary_canvas_hand_pans_while_a_transform_is_open() { assert_eq!(box_key(&app), box_before, "the drag didn't touch the box"); } +/// The canvas can paint a batch as a nested list, which keeps its place in egui's final paint order. +fn flattened_paint_shapes(output: &egui::FullOutput) -> Vec<&egui::Shape> { + fn open<'a>(shape: &'a egui::Shape, into: &mut Vec<&'a egui::Shape>) { + match shape { + egui::Shape::Vec(list) => list.iter().for_each(|shape| open(shape, into)), + shape => into.push(shape), + } + } + let mut shapes = Vec::new(); + for clipped in &output.shapes { + open(&clipped.shape, &mut shapes); + } + shapes +} + #[test] fn guides_draw_over_the_transform_preview_and_under_its_box() { // #5086: a guide crossing a layer under Free Transform was hidden behind the preview of @@ -692,16 +707,7 @@ fn guides_draw_over_the_transform_preview_and_under_its_box() { // At 100 % centred on the document, screen and document coordinates coincide. let layer = Rect::from_min_max(pos2(100.0, 100.0), pos2(200.0, 160.0)); let near = |r: Rect| (r.min - layer.min).length() < 1.0 && (r.max - layer.max).length() < 1.0; - fn open<'a>(shape: &'a egui::Shape, into: &mut Vec<&'a egui::Shape>) { - match shape { - egui::Shape::Vec(list) => list.iter().for_each(|shape| open(shape, into)), - shape => into.push(shape), - } - } - let mut shapes = Vec::new(); - for clipped in &out.shapes { - open(&clipped.shape, &mut shapes); - } + let shapes = flattened_paint_shapes(&out); let position = |pred: &dyn Fn(&egui::Shape) -> bool| shapes.iter().position(|s| pred(s)); // The moving pixels: the mesh that spans the layer's box. let preview = position(&|s| matches!(s, egui::Shape::Mesh(m) if near(m.calc_bounds()))); @@ -716,6 +722,74 @@ fn guides_draw_over_the_transform_preview_and_under_its_box() { assert!(guide < frame, "the box ({frame}) draws over the guide ({guide})"); } +#[test] +fn marching_ants_draw_over_a_guide_on_the_selection_edge() { + use craft::behavior::kurbo::Point; + + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + let ctx = app.ctx().clone(); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("select.rect", json!({"x": 100, "y": 100, "width": 100, "height": 60})).unwrap(); + app.run("view.newGuide", json!({"orientation": "vertical", "position": 100})).unwrap(); + app.ui.tool = Tool::RectMarquee; + app.ui.extras.rulers = false; + app.ui.extras.grid = false; + app.ui.extras.guides = true; + app.ui.view.extras = true; + app.ui.view.show.canvas_guides = true; + app.ui.view.show.selection_edges = true; + app.sync_views(); + + let mut view = app.ui.views[0].clone(); + view.zoom = 1.0; + view.center = [200.0, 150.0]; + view.clear_pending(); + let rect = Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0)); + let draw = |app: &mut PhotocraftApp| { + let input = egui::RawInput { screen_rect: Some(rect), ..Default::default() }; + let mut output = ctx.run_ui(input, |ui| { + canvas_view(app, ui, CanvasHost::main(0), rect, view.clone(), true); + }); + output.textures_delta.clear(); + output + }; + + let output = draw(&mut app); + let shown = active_view(&app).expect("the canvas view"); + let edge = Rect::from_two_pos(shown.to_screen(Point::new(100.0, 100.0)), shown.to_screen(Point::new(100.0, 160.0))); + let pixel = output.pixels_per_point.recip(); + let is_guide = |shape: &egui::Shape| { + let egui::Shape::LineSegment { points, .. } = shape else { return false }; + points.iter().all(|p| (p.x - edge.left()).abs() <= pixel) + && points[0].y.min(points[1].y) < edge.top() - pixel + && points[0].y.max(points[1].y) > edge.bottom() + pixel + }; + let is_ants = |shape: &egui::Shape| { + let bounds = match shape { + egui::Shape::Mesh(mesh) => mesh.calc_bounds(), + egui::Shape::Rect(rect) => rect.rect, + egui::Shape::LineSegment { points, .. } => Rect::from_two_pos(points[0], points[1]), + _ => return false, + }; + // A strip or dash on the selection edge, allowing for the framework's device-pixel snap. + bounds.height() > 0.0 + && bounds.width() <= 2.0 * pixel + && (bounds.center().x - edge.left()).abs() <= pixel + && bounds.top() >= edge.top() - pixel + && bounds.bottom() <= edge.bottom() + 2.0 * pixel + }; + let shapes = flattened_paint_shapes(&output); + let guide = shapes.iter().position(|shape| is_guide(shape)).expect("the guide spanning the selection"); + let ants = shapes.iter().position(|shape| is_ants(shape)).expect("the ants along the left edge"); + assert!(guide < ants, "the guide ({guide}) paints before the ants ({ants})"); + + app.ui.view.show.selection_edges = false; + let output = draw(&mut app); + let shapes = flattened_paint_shapes(&output); + assert!(shapes.iter().any(|shape| is_guide(shape)), "hiding selection edges leaves the guide"); + assert!(!shapes.iter().any(|shape| is_ants(shape)), "the edge paint belongs to the ants"); +} + #[test] fn layer_style_dialog_previews_live_and_cancel_restores() { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); From c3a6cbf4a37b0e0a5ab977281ff5a7e5f8b99ff5 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:32:31 +0100 Subject: [PATCH 2/2] Verify app shortcuts recover when a recorder closes --- .../prefs/prefs_ui/shortcut_capture_tests.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index 7d46727407..8ede607906 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -6,6 +6,7 @@ use craft::keymap::{Binding, CommandRef, Policy}; use egui::{Event, Key, Modifiers}; use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; use photocraft_engine::prefs::{bindable_items, normalize_shortcut}; use serde_json::json; @@ -73,6 +74,37 @@ fn toolbar_shortcut_can_be_captured_and_restored_on_restart() { assert_eq!(restarted.state().ui.tool, crate::state::Tool::Pencil); } +#[test] +fn closing_keyboard_shortcuts_while_recording_restores_app_hotkeys() { + use crate::state::Tool; + + let mut session = photocraft_engine::Session::new(); + session.prefs.edit(|p| p.interface.language = "en".into()); + let mut h = harness_with(session); + edit_and_ok(&mut h, "tools.select.pencil", "F6"); + h.state_mut().ui.tool = Tool::Move; + crate::prefs_ui::open_shortcuts(h.state_mut(), 0); + h.run_steps(2); + + h.get_by_label("Search by key").click(); + h.run_steps(2); + assert!(crate::prefs_ui::recording(h.state()), "the recorder is waiting for a key"); + tap(&mut h, Key::F6, Modifiers::NONE); + assert!(h.query_all_by_label("Search:").any(|node| node.accesskit_node().value().as_deref() == Some("F6")), "the recorder took F6"); + assert_eq!(h.state().ui.tool, Tool::Move, "F6 leaves the tool alone during recording"); + assert!(!crate::prefs_ui::recording(h.state()), "the chord ended the search recording"); + + h.get_by_label("Search by key").click(); + h.run_steps(2); + assert!(crate::prefs_ui::recording(h.state()), "recording again before the dialog closes"); + assert!(super::shortcuts::cancel(h.state_mut()), "Cancel closes the active dialog"); + h.run_steps(2); + assert!(!crate::prefs_ui::shortcuts_open(h.state()), "the modal is gone"); + + tap(&mut h, Key::F6, Modifiers::NONE); + assert_eq!(h.state().ui.tool, Tool::Pencil, "F6 selects Pencil again after the dialog closes"); +} + #[test] fn toolbar_shortcut_overrides_remove_old_keys_and_skip_removed_group_members() { use crate::state::Tool;