From 841293ebe098b0a064a5ac56a9b33f569989d01e Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Tue, 10 Nov 2026 18:48:09 +0300 Subject: [PATCH 1/2] Rasterize prompt: a painting tool's type prompt adds "Rasterize Layer" (#12888) OK on the type-layer prompt a painting tool raises now names the history state its rasterize added "Rasterize Layer", as the reference application does. Layer > Rasterize > Type keeps "Rasterize Type"; the shape, Smart Object and fill prompts and the filter prompt are unchanged. --- crates/ui-egui/src/dialogs/rasterize_prompt.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt.rs b/crates/ui-egui/src/dialogs/rasterize_prompt.rs index d77d259692..2f339b0ee9 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt.rs @@ -207,7 +207,15 @@ pub fn confirm(app: &mut PhotocraftApp, f: &Map) -> Result Date: Tue, 10 Nov 2026 18:48:09 +0300 Subject: [PATCH 2/2] Tests: the rasterize prompt's history step name (#12888) --- .../ui-egui/src/dialogs/rasterize_prompt.rs | 4 + .../src/dialogs/rasterize_prompt/tests.rs | 18 +-- .../rasterize_prompt_history_name_tests.rs | 104 ++++++++++++++++++ 3 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 crates/ui-egui/src/rasterize_prompt_history_name_tests.rs diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt.rs b/crates/ui-egui/src/dialogs/rasterize_prompt.rs index 2f339b0ee9..c099f6b76e 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt.rs @@ -255,3 +255,7 @@ mod rasterize_prompt_text_tests; #[cfg(test)] #[path = "rasterize_prompt_fill_text_tests.rs"] mod rasterize_prompt_fill_text_tests; + +#[cfg(test)] +#[path = "../rasterize_prompt_history_name_tests.rs"] +mod rasterize_prompt_history_name_tests; diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs b/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs index b270f31ec1..a211085791 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs @@ -6,7 +6,7 @@ use super::*; use crate::canvas::{ToolEvent, tool_event}; /// A document whose active layer is a `kind` layer over a white Background. -fn app_with(kind: Kind) -> PhotocraftApp { +pub(super) fn app_with(kind: Kind) -> PhotocraftApp { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); app.run("file.new", json!({"width": 120, "height": 80})).unwrap(); match kind { @@ -28,21 +28,21 @@ fn app_with(kind: Kind) -> PhotocraftApp { app } -fn active_content(app: &PhotocraftApp) -> &'static str { +pub(super) fn active_content(app: &PhotocraftApp) -> &'static str { let st = app.session.active().unwrap(); st.doc.layer(st.active_layer.unwrap()).unwrap().content.kind_name() } -fn past(app: &PhotocraftApp) -> usize { +pub(super) fn past(app: &PhotocraftApp) -> usize { app.session.active().unwrap().history.past_len() } -fn click(app: &mut PhotocraftApp, x: f64, y: f64) { +pub(super) fn click(app: &mut PhotocraftApp, x: f64, y: f64) { tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, Modifiers::NONE); tool_event(app, ToolEvent::Up { x, y }, Modifiers::NONE); } -fn prompt(app: &PhotocraftApp) -> Option<&crate::state::Dialog> { +pub(super) fn prompt(app: &PhotocraftApp) -> Option<&crate::state::Dialog> { app.ui.dialogs.iter().find(|d| owns(&d.fields)) } @@ -178,14 +178,14 @@ fn the_control_channel_sees_and_confirms_the_prompt() { assert_eq!(active_content(&app), "Pixel"); } -const BLUR: &str = "filter.blur.gaussianBlur"; +pub(super) const BLUR: &str = "filter.blur.gaussianBlur"; -fn menu(app: &mut PhotocraftApp, id: &str) -> Result { +pub(super) fn menu(app: &mut PhotocraftApp, id: &str) -> Result { crate::menus::invoke(app, &egui::Context::default(), id, json!({})) } /// Answers the filter prompt, then the frame runs the queued filter. -fn answer(app: &mut PhotocraftApp, id: u64) { +pub(super) fn answer(app: &mut PhotocraftApp, id: u64) { crate::dialogs::confirm(app, id).unwrap(); run_pending(app, &egui::Context::default()); } @@ -276,7 +276,7 @@ fn filters_stay_grey_where_rasterizing_would_not_help() { } /// The dialogs, and the filter a prompt queued, frame by frame. -fn harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> { +pub(super) fn harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> { let h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_ui_state( |ui, app| { crate::dialogs::show(app, ui.ctx()); diff --git a/crates/ui-egui/src/rasterize_prompt_history_name_tests.rs b/crates/ui-egui/src/rasterize_prompt_history_name_tests.rs new file mode 100644 index 0000000000..97fb345826 --- /dev/null +++ b/crates/ui-egui/src/rasterize_prompt_history_name_tests.rs @@ -0,0 +1,104 @@ +//! #12888: OK on the type-layer prompt a painting tool raises adds one history state named +//! "Rasterize Layer", as the reference application does; Layer › Rasterize › Type, Cancel and +//! the shape, Smart Object and fill prompts keep their behaviour. + +use egui_kittest::kittest::Queryable; +use serde_json::{Value, json}; + +use super::tests::{BLUR, active_content, answer, app_with, click, harness, menu, past, prompt}; +use super::*; + +fn step_name(app: &PhotocraftApp) -> Option { + app.session.active()?.history.undo_label().map(str::to_string) +} + +fn active_layer_content(app: &PhotocraftApp) -> photocraft_doc::LayerContent { + let st = app.session.active().unwrap(); + st.doc.layer(st.active_layer.unwrap()).unwrap().content.clone() +} + +/// A press of `tool` on a `kind` layer, answered with `button` in the dialog. +fn answer_prompt(kind: Kind, tool: Tool, button: &str) -> (PhotocraftApp, usize) { + let mut app = app_with(kind); + app.ui.tool = tool; + let before = past(&app); + // The harness's first frame installs the fonts, so the press comes after it. + let mut h = harness(app); + click(h.state_mut(), 30.0, 20.0); + assert!(prompt(h.state()).is_some(), "{kind:?}/{tool:?}: the prompt opens"); + h.run_steps(4); + h.get_by_label(button).click(); + h.run_steps(4); + let app = h.into_state(); + assert!(prompt(&app).is_none(), "{kind:?}/{tool:?}: {button} closes the prompt"); + (app, before) +} + +#[test] +fn ok_from_a_painting_tool_adds_one_rasterize_layer_state() { + for tool in [Tool::PatternStamp, Tool::Brush, Tool::HistoryBrush] { + let (app, before) = answer_prompt(Kind::Type, tool, "OK"); + assert_eq!(past(&app), before + 1, "{tool:?}: exactly one state"); + assert_eq!(step_name(&app).as_deref(), Some("Rasterize Layer"), "{tool:?}"); + assert_eq!(active_content(&app), "Pixel", "{tool:?}: the layer is rasterized"); + // Nothing painted: the pixels are the plain rasterized type. + let mut plain = app_with(Kind::Type); + plain.run("layer.rasterize.type", json!({})).unwrap(); + assert!(active_layer_content(&app) == active_layer_content(&plain), "{tool:?}: the press painted nothing"); + // The name belongs to the history state: undone, it is the state to redo. + let mut app = app; + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.active().unwrap().history.redo_labels().next(), Some("Rasterize Layer"), "{tool:?}"); + } +} + +#[test] +fn cancel_adds_no_state() { + for tool in [Tool::PatternStamp, Tool::Brush, Tool::HistoryBrush] { + let (app, before) = answer_prompt(Kind::Type, tool, "Cancel"); + assert_eq!(past(&app), before, "{tool:?}"); + assert_eq!(active_content(&app), "Type", "{tool:?}"); + } +} + +#[test] +fn layer_rasterize_type_keeps_its_step_name() { + let mut app = app_with(Kind::Type); + crate::menus::invoke(&mut app, &egui::Context::default(), "layer.rasterize.type", json!({})).unwrap(); + assert_eq!(step_name(&app).as_deref(), Some("Rasterize Type"), "the menu"); + + let ctx = egui::Context::default(); + for (method, params) in [("ui.menu.invoke", json!({"id": "layer.rasterize.type"})), ("engine.execute", json!({"command": "layer.rasterize.type"}))] { + let mut app = app_with(Kind::Type); + let (req, _rx) = crate::control::ControlRequest::new(method, params); + let crate::control::Outcome::Done(r) = crate::control::handle(&mut app, &ctx, &req) else { panic!("{method}: deferred") }; + assert_ne!(r.get("ok"), Some(&Value::Bool(false)), "{method}: {r}"); + assert_eq!(active_content(&app), "Pixel", "{method}"); + assert_eq!(step_name(&app).as_deref(), Some("Rasterize Type"), "{method}"); + } +} + +#[test] +fn the_other_prompts_keep_their_step_names() { + for kind in [Kind::Shape, Kind::SmartObject, Kind::Fill] { + let mut direct = app_with(kind); + direct.run(kind.command(), json!({})).unwrap(); + let (app, before) = answer_prompt(kind, Tool::Brush, "OK"); + assert_eq!(past(&app), before + 1, "{kind:?}"); + assert_eq!(step_name(&app), step_name(&direct), "{kind:?}"); + assert_ne!(step_name(&app).as_deref(), Some("Rasterize Layer"), "{kind:?}"); + } +} + +/// The filter prompt's Rasterize (#4303) is not measured: its step keeps "Rasterize Type". +#[test] +fn the_filter_prompt_keeps_rasterize_type() { + let mut app = app_with(Kind::Type); + let before = past(&app); + menu(&mut app, BLUR).unwrap(); + let id = prompt(&app).expect("the prompt").id; + answer(&mut app, id); + assert_eq!(active_content(&app), "Pixel"); + assert_eq!(past(&app), before + 1); + assert_eq!(step_name(&app).as_deref(), Some("Rasterize Type")); +}