From 0d4b939d41634a0835f31667bbaedfddb1704b08 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Tue, 24 Nov 2026 01:17:41 +0100 Subject: [PATCH 1/4] fix(ui): Patch on a Type layer opens the rasterize prompt (#12121) A patch drag that started inside the selection ran `paint.patch` straight away, so on a live Type layer the engine's `enabled` check answered "active layer is a Type layer, not a pixel layer" in the status bar and no question was asked, while the painting tools ask first. `finish_patch` now opens the existing rasterize prompt when the drag targets the pixels of an unlocked Type layer, carrying the params that drag had worked out: OK rasterizes the layer and re-runs the patch on it, Cancel leaves the layer, the selection and the History untouched. The Content-Aware option, a targeted layer mask and Shape, Smart Object and fill layers keep today's behaviour, which the issue did not measure. --- .../ui-egui/src/dialogs/rasterize_prompt.rs | 42 +++- crates/ui-egui/src/lib.rs | 2 + .../src/patch_rasterize_prompt_tests.rs | 229 ++++++++++++++++++ crates/ui-egui/src/tools/retouch_ui.rs | 9 + 4 files changed, 274 insertions(+), 8 deletions(-) create mode 100644 crates/ui-egui/src/patch_rasterize_prompt_tests.rs diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt.rs b/crates/ui-egui/src/dialogs/rasterize_prompt.rs index ae1bc659cd..f1427f249f 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt.rs @@ -6,7 +6,8 @@ //! The prompt is a `StandardPrompt` on the dialog host (`ui.inspect` shows it, `ui.dialog.confirm` //! and `ui.dialog.cancel` answer it). OK runs the matching `layer.rasterize.*` command and nothing //! else: the click that opened the prompt is not replayed, as in Photoshop (#8806), so the next -//! click paints. Cancel does nothing. +//! click paints. Cancel does nothing. The Patch tool's prompt is the exception (#12121): its drag is +//! over when that prompt opens, so OK also applies the `paint.patch` the drag worked out. //! //! A filter on a type layer asks the same question (#4303), with Photoshop's Convert to Smart //! Object / Rasterize / Cancel: the layer is converted or rasterized, then the filter is chosen @@ -30,12 +31,13 @@ pub enum Kind { } /// What the prompt asked about: rasterize `layer` (a `kind` layer); with `filter`, then run that -/// filter and its params on it. +/// filter and its params on it; with `patch`, then run `paint.patch` with those params (#12121). // Whether Convert is offered is fixed when the prompt opens (the button exists or not), so the tag does not carry it. pub(crate) struct Rasterize { kind: Kind, layer: u64, filter: Option<(String, Value)>, + patch: Option, } impl Kind { @@ -113,6 +115,18 @@ pub fn intercept(app: &mut PhotocraftApp, tool: Tool, x: f64, y: f64, pressure: true } +/// Opens the same question for a Patch drag on a `layer` that must be rasterized first: OK rasterizes +/// it and then runs `paint.patch` with `params`, the params the finished drag had worked out, so the +/// patch lands on the rasterized layer (#12121). Cancel does nothing. +pub fn open_patch(app: &mut PhotocraftApp, kind: Kind, layer: photocraft_doc::LayerId, params: Value) -> DialogId { + let prompt = StandardPrompt::custom(tl!(kind.message()).to_owned()) + .title(tl!("PhotoCraft").to_owned()) + .button(PromptChoice::Proceed, tl!("OK").to_owned()) + .button(PromptChoice::Cancel, tl!("Cancel").to_owned()) + .tag(Rasterize { kind, layer: layer.0, filter: None, patch: Some(params) }); + alerts::open_prompt(app, prompt).unwrap_or_else(|open| open) +} + /// Opens the prompt for `layer`; OK rasterizes it, and the id of the prompt already open comes back /// when there is one. `tool` and `at` (x, y, pressure) name the press that opened it; the press is /// never replayed, so they change nothing. @@ -121,7 +135,7 @@ pub fn open(app: &mut PhotocraftApp, kind: Kind, layer: photocraft_doc::LayerId, .title(tl!("PhotoCraft").to_owned()) .button(PromptChoice::Proceed, tl!("OK").to_owned()) .button(PromptChoice::Cancel, tl!("Cancel").to_owned()) - .tag(Rasterize { kind, layer: layer.0, filter: None }); + .tag(Rasterize { kind, layer: layer.0, filter: None, patch: None }); alerts::open_prompt(app, prompt).unwrap_or_else(|open| open) } @@ -166,6 +180,7 @@ pub fn intercept_filter(app: &mut PhotocraftApp, id: &str, params: &Value) -> Op kind: Kind::Type, layer: layer.0, filter: Some((id.to_owned(), params.clone())), + patch: None, }); let dialog = alerts::open_prompt(app, prompt).unwrap_or_else(|open| open); Some(Ok(json!({"dialog": dialog.value()}))) @@ -173,12 +188,15 @@ pub fn intercept_filter(app: &mut PhotocraftApp, id: &str, params: &Value) -> Op /// The `PROMPTS` entry: Proceed rasterizes, Alternate converts to a Smart Object (the filter prompt /// only), Cancel does nothing. The filter of a filter prompt runs at once, as the menu would, now -/// that the layer can take it. `false` for another family's answer. +/// that the layer can take it. A patch prompt's Proceed runs `paint.patch` on the layer it just +/// rasterized (#12121). `false` for another family's answer. pub(crate) fn answer(app: &mut PhotocraftApp, ctx: &egui::Context, answer: &mut PromptAnswer) -> bool { - let Some(Rasterize { kind, layer, filter }) = answer.take_tag::() else { return false }; - let result = match (answer.choice, filter) { - (PromptChoice::Proceed, None) => rasterize(app, kind, layer), - (PromptChoice::Proceed | PromptChoice::Alternate, Some((filter, params))) => { + let Some(Rasterize { kind, layer, filter, patch }) = answer.take_tag::() else { return false }; + let result = match (answer.choice, filter, patch) { + (PromptChoice::Proceed, None, None) => rasterize(app, kind, layer), + // The Patch drag had already ended when this prompt opened, so its params re-run here. + (PromptChoice::Proceed, None, Some(params)) => rasterize_then_patch(app, kind, layer, params), + (PromptChoice::Proceed | PromptChoice::Alternate, Some((filter, params)), None) => { convert_for_filter(app, ctx, answer.choice == PromptChoice::Alternate, &filter, params, layer) } _ => return true, @@ -203,6 +221,14 @@ fn rasterize(app: &mut PhotocraftApp, kind: Kind, layer: u64) -> Result Result { + let rasterized = rasterize(app, kind, layer)?; + let patch = app.run("paint.patch", params)?; + Ok(json!({ "rasterized": rasterized, "patched": patch })) +} + /// The filter prompt's answer: convert (`smart`) or rasterize the layer, then run the filter. fn convert_for_filter(app: &mut PhotocraftApp, ctx: &egui::Context, smart: bool, filter: &str, params: Value, layer: u64) -> Result { let command = if smart { "layer.smartObjects.convertToSmartObject" } else { Kind::Type.command() }; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 971b53a218..fd884902ac 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -739,6 +739,8 @@ mod eyedropper_context_menu_tests; #[cfg(test)] mod menu_automate_groups_tests; #[cfg(test)] +mod patch_rasterize_prompt_tests; +#[cfg(test)] mod patch_shift_constrain_tests; #[cfg(test)] mod paths_scroll_tests; diff --git a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs new file mode 100644 index 0000000000..b097a62bf5 --- /dev/null +++ b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs @@ -0,0 +1,229 @@ +//! #12121: dragging the Patch selection on a Type layer asks the rasterize question, as the +//! painting tools do, instead of refusing in the status bar. OK rasterizes the layer and applies +//! the patch the drag worked out; Cancel changes nothing. A lasso drag with the Patch tool still +//! only makes the selection. Shape layers, Content-Aware mode and a targeted mask are *not +//! measured* in the issue and keep today's behaviour, pinned here. + +use craft::ui::dialog::DialogId; +use egui::Modifiers; +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::dialogs::alerts; +use crate::rasterize_prompt::Rasterize; +use crate::state::Tool; + +/// A 200 x 120 document whose active layer holds `kind` content (a Type, Shape, Smart Object or +/// fill layer, or plain pixels), the Patch tool active, and a hard 40 x 30 rectangle selected at +/// 40,40. +fn app(kind: &str) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + // The rasterize step and the patch settle in the pass that asks for them. + app.background_jobs = false; + app.run("file.new", json!({"width": 200, "height": 120, "background": "white"})).unwrap(); + match kind { + "Type" => app.run("type.create", json!({"x": 20, "y": 60, "text": "Hello world"})).map(|_| ()), + "Shape" => app.run("shape.create", json!({"kind": "rect", "rect": [20, 40, 90, 70], "fill": "#ff0000"})).map(|_| ()), + "Smart Object" => { + app.run("layer.new.layer", json!({})).unwrap(); + app.run("edit.fill", json!({"color": "#00ff00"})).unwrap(); + app.run("layer.smartObjects.convertToSmartObject", json!({})).map(|_| ()) + } + "Fill" => app.run("layer.newFillLayer.solidColor", json!({"color": "#00ff00"})).map(|_| ()), + _ => Ok(()), + } + .unwrap(); + app.run("select.rect", json!({"x": 40, "y": 40, "width": 40, "height": 30, "mode": "replace"})).unwrap(); + // The layer's own pixels, not its mask. + app.ui.mask_target = false; + app.sync_mask_targets(); + app.ui.tool = Tool::Patch; + app.ui.tool_options.patch_content_aware = false; + app +} + +/// Drags the patch from inside the selection at 55,50 to 115,50: the offset 60,0. +fn drag_patch(app: &mut PhotocraftApp) { + let m = Modifiers::NONE; + tool_event(app, ToolEvent::Down { x: 55.0, y: 50.0, pressure: 1.0 }, m); + tool_event(app, ToolEvent::Move { x: 80.0, y: 50.0, pressure: 1.0 }, m); + tool_event(app, ToolEvent::Move { x: 115.0, y: 50.0, pressure: 1.0 }, m); + tool_event(app, ToolEvent::Up { x: 115.0, y: 50.0 }, m); +} + +/// The open rasterize prompt, whichever family opened it. +fn prompt(app: &PhotocraftApp) -> Option { + alerts::prompt_tagged::(app) +} + +/// OK on the open prompt, as `ui.dialog.confirm` does: the answer acts inside the call. +fn answer(app: &mut PhotocraftApp, id: DialogId) { + let ctx = app.ctx().clone(); + crate::dialogs::confirm(app, &ctx, id).unwrap(); +} + +/// The params of every `paint.patch` in the History. +fn patch_params(app: &PhotocraftApp) -> Vec { + app.session.journal.iter().filter(|(id, _)| id == "paint.patch").map(|(_, p)| p.clone()).collect() +} + +fn past(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.past_len() +} + +/// The active layer's content, as "Type", "Shape", "Pixel" ... +fn active_content(app: &PhotocraftApp) -> &'static str { + let st = app.session.active().unwrap(); + st.doc.layer(st.active_layer.unwrap()).unwrap().content.kind_name() +} + +/// The selected area as [x, y, width, height], for the Destination mode's moved selection. +fn selection_bounds(app: &PhotocraftApp) -> [i32; 4] { + let sel = app.session.active().unwrap().doc.selection.clone().unwrap(); + let b = sel.content_bounds(); + [b.x0, b.y0, b.x1 - b.x0, b.y1 - b.y0] +} + +/// Done when 1: the drag on a Type layer asks instead of refusing; nothing happens until the answer. +#[test] +fn a_patch_drag_on_a_type_layer_asks_to_rasterize_first() { + let mut app = app("Type"); + let before = (past(&app), selection_bounds(&app)); + drag_patch(&mut app); + prompt(&app).unwrap_or_else(|| panic!("the patch drag opened no prompt; status: {}", app.ui.status)); + assert!(!app.ui.status_error, "the question stands in place of the status-bar refusal: {}", app.ui.status); + assert_eq!(active_content(&app), "Type", "the layer waits for the answer"); + assert_eq!(past(&app), before.0, "nothing is recorded before the answer"); + assert_eq!(selection_bounds(&app), before.1, "the selection is where the drag left it"); + assert!(patch_params(&app).is_empty(), "no patch ran"); + assert!(!crate::patch_preview::showing(&app), "the healed preview is off the canvas once the question is up"); + // A second drag while the question is up does not stack another prompt. + drag_patch(&mut app); + assert_eq!(app.framework.dialogs.open_dialogs().len(), 1, "{:?}", app.framework.dialogs.open_dialogs()); +} + +/// Done when 1: OK rasterizes the layer and applies the patch the drag worked out. Destination +/// mode also moves the selection, which proves the patch ran without depending on the glyphs. +#[test] +fn ok_rasterizes_the_layer_and_applies_the_patch() { + let mut app = app("Type"); + app.ui.tool_options.patch_mode = "destination".into(); + let before = (past(&app), selection_bounds(&app)); + drag_patch(&mut app); + let id = prompt(&app).expect("the prompt"); + answer(&mut app, id); + assert!(!app.ui.status_error, "{}", app.ui.status); + assert_eq!(active_content(&app), "Pixel", "OK rasterizes the type layer"); + assert_eq!(past(&app), before.0 + 2, "rasterize, then the patch"); + assert_eq!(patch_params(&app), vec![json!({"offset": [60, 0], "mode": "destination", "target": "pixels"})]); + let [x, y, w, h] = before.1; + assert_eq!(selection_bounds(&app), [x + 60, y, w, h], "the patch ran on the rasterized layer"); + assert!(app.session.active().unwrap().doc.layer(app.session.active().unwrap().active_layer.unwrap()).unwrap().surface().is_some()); + // One undo takes the patch back and keeps the rasterized layer. + app.session.undo(); + assert_eq!(active_content(&app), "Pixel"); + assert_eq!(selection_bounds(&app), [x, y, w, h]); + app.session.undo(); + assert_eq!(active_content(&app), "Type"); +} + +/// Done when 1: Cancel leaves the Type layer, the selection and the History exactly as they were. +#[test] +fn cancel_changes_nothing() { + let mut app = app("Type"); + let before = (past(&app), app.session.active().unwrap().doc.clone()); + drag_patch(&mut app); + let id = prompt(&app).expect("the prompt"); + let ctx = app.ctx().clone(); + crate::dialogs::cancel(&mut app, &ctx, id).unwrap(); + assert!(prompt(&app).is_none()); + assert!(app.framework.dialogs.is_empty()); + assert_eq!(past(&app), before.0); + assert_eq!(*app.session.active().unwrap().doc, *before.1, "the document is untouched"); + assert_eq!(active_content(&app), "Type"); + assert!(patch_params(&app).is_empty()); +} + +/// Done when 2: a lasso drag with the Patch tool on a Type layer only makes the selection. +#[test] +fn a_lasso_drag_makes_the_selection_without_asking() { + let mut app = app("Type"); + let m = Modifiers::NONE; + // Outside the selection, so this is a lasso and not a patch drag. + tool_event(&mut app, ToolEvent::Down { x: 120.0, y: 80.0, pressure: 1.0 }, m); + for [x, y] in [[180.0, 80.0], [180.0, 110.0], [150.0, 110.0]] { + tool_event(&mut app, ToolEvent::Move { x, y, pressure: 1.0 }, m); + } + tool_event(&mut app, ToolEvent::Up { x: 150.0, y: 110.0 }, m); + assert!(prompt(&app).is_none(), "the outline makes a selection, it does not paint"); + assert!(patch_params(&app).is_empty()); + assert!(!app.ui.status_error, "{}", app.ui.status); + let sel = app.session.active().unwrap().doc.selection.clone().unwrap(); + assert!(sel.sample_channel(160, 95, 0) > 0.0, "the lasso replaced the selection"); + assert_eq!(sel.sample_channel(55, 50, 0), 0.0, "the rectangle is gone"); + assert_eq!(active_content(&app), "Type"); +} + +/// Not measured: a patch of the type layer's own mask paints no pixels, so it still runs unasked. +#[test] +fn a_type_layers_mask_still_takes_the_patch() { + let mut app = app("Type"); + app.run("layer.layerMask.revealAll", json!({})).unwrap(); + app.ui.mask_target = true; + app.sync_mask_targets(); + let before = past(&app); + drag_patch(&mut app); + assert!(prompt(&app).is_none(), "the mask needs no rasterizing"); + assert!(!app.ui.status_error, "{}", app.ui.status); + assert_eq!(patch_params(&app), vec![json!({"offset": [60, 0], "mode": "source", "target": "mask"})]); + assert_eq!(past(&app), before + 1, "the mask patch is one step"); + assert_eq!(active_content(&app), "Type", "the layer stays editable"); +} + +/// Not measured: Content-Aware mode on a Type layer keeps today's status-bar refusal. +#[test] +fn content_aware_mode_on_a_type_layer_still_refuses() { + let mut app = app("Type"); + app.ui.tool_options.patch_content_aware = true; + let before = past(&app); + drag_patch(&mut app); + assert!(prompt(&app).is_none(), "Content-Aware mode on a type layer was not measured"); + assert!(app.ui.status_error, "the refusal is still reported: {}", app.ui.status); + assert!(app.ui.status.contains("Type layer"), "unexpected refusal: {}", app.ui.status); + assert!(patch_params(&app).is_empty()); + assert_eq!(past(&app), before); + assert_eq!(active_content(&app), "Type"); +} + +/// Not measured: a Shape, Smart Object or fill layer keeps today's status-bar refusal, no prompt. A +/// fill layer carries a mask, so the engine's own check lets it through and its surface lookup is +/// what says "not a pixel layer"; the wording differs from the other two and is pinned as it is. +#[test] +fn the_other_layer_kinds_still_refuse() { + for (kind, words) in + [("Shape", "a Shape layer, not a pixel layer"), ("Smart Object", "a Smart Object layer, not a pixel layer"), ("Fill", "not a pixel layer")] + { + let mut app = app(kind); + let before = past(&app); + drag_patch(&mut app); + assert!(prompt(&app).is_none(), "{kind}: no prompt was measured for it"); + assert!(app.ui.status_error, "{kind}: the refusal is still reported: {}", app.ui.status); + assert!(app.ui.status.contains(words), "{kind}: unexpected refusal: {}", app.ui.status); + assert!(patch_params(&app).is_empty(), "{kind}"); + assert_eq!(past(&app), before, "{kind}"); + assert_eq!(active_content(&app), kind, "{kind} stays editable"); + } +} + +/// A pixel layer is unaffected: the patch applies with no question asked. +#[test] +fn a_pixel_layer_patch_still_applies_without_asking() { + let mut app = app("Pixel"); + let before = past(&app); + drag_patch(&mut app); + assert!(prompt(&app).is_none()); + assert!(!app.ui.status_error, "{}", app.ui.status); + assert_eq!(patch_params(&app), vec![json!({"offset": [60, 0], "mode": "source", "target": "pixels"})]); + assert_eq!(past(&app), before + 1); +} diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index ab272483bf..e4441ec602 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -476,6 +476,15 @@ pub fn finish_patch(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) { return; } let p = json!({"offset": off, "mode": app.ui.tool_options.patch_mode, "target": crate::canvas::paint_target(app)}); + // #12121: on a Type layer the reference asks its rasterize question instead of refusing, and OK + // applies this very patch on the layer it just rasterized. Only the measured case asks: the + // layer's own pixels in plain mode. Every other target and layer kind keeps the engine's refusal. + if let Some((kind, layer)) = crate::rasterize_prompt::needed(app) + && kind == crate::rasterize_prompt::Kind::Type + { + crate::rasterize_prompt::open_patch(app, kind, layer, p); + return; + } match app.run("paint.patch", p) { Ok(_) => crate::patch_preview::committed(app, preview, off), Err(e) => { From f752e6d0a733c1b744b6a061115c31e4f00584f2 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Tue, 24 Nov 2026 03:36:19 +0100 Subject: [PATCH 2/4] fix(ui): keep the rasterize prompt off hidden and stale patch targets A hidden Type layer took the question, and OK rasterized it while the engine refused the patch, so the text was gone and nothing was healed. The gate now asks the engine's own hidden-target check (`hidden_target::refusal` for `paint.patch`, which walks the layer and the groups around it) before opening the prompt, so a hidden target keeps today's clean refusal and its document stays untouched. The replayed params name no layer, so OK also re-checks that the active layer is still the one the question was about: the rasterize settles that layer, and a different one now gets a status error instead of the patch. --- .../ui-egui/src/dialogs/rasterize_prompt.rs | 6 ++ .../src/patch_rasterize_prompt_tests.rs | 63 +++++++++++++++++++ crates/ui-egui/src/tools/retouch_ui.rs | 5 +- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt.rs b/crates/ui-egui/src/dialogs/rasterize_prompt.rs index f1427f249f..5f13fb2549 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt.rs @@ -225,6 +225,12 @@ fn rasterize(app: &mut PhotocraftApp, kind: Kind, layer: u64) -> Result Result { let rasterized = rasterize(app, kind, layer)?; + // The patch params name no layer: run as they stand, its pixels go to whatever is active when OK + // comes. The rasterize above settled the layer the question was about, so a different active + // layer now refuses the patch instead of painting somewhere else (#12121). + if app.session.active().and_then(|st| st.active_layer).map(|id| id.0) != Some(layer) { + return Err("the layer this question was about is no longer the active layer, so the patch was not applied".into()); + } let patch = app.run("paint.patch", params)?; Ok(json!({ "rasterized": rasterized, "patched": patch })) } diff --git a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs index b097a62bf5..dc6b2ebca6 100644 --- a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs +++ b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs @@ -216,6 +216,69 @@ fn the_other_layer_kinds_still_refuse() { } } +/// Review round: a Type layer that is hidden, or sits in a hidden group, keeps today's refusal. The +/// engine never writes there, so a prompt would only let OK destroy the text for no patch. +#[test] +fn a_hidden_type_layer_is_refused_without_a_prompt() { + for group in [false, true] { + let mut app = app("Type"); + let text = app.session.active().unwrap().active_layer.unwrap(); + if group { + let wrapped = app.run("layer.new.group", json!({"name": "Wrapped"})).unwrap()["layer"].as_u64().unwrap(); + app.run("layer.moveTo", json!({"layer": text.0, "target": wrapped, "position": "into"})).unwrap(); + app.run("layer.hideLayers", json!({"layer": wrapped})).unwrap(); + } else { + app.run("layer.hideLayers", json!({"layer": text.0})).unwrap(); + } + let what = if group { "type layer in a hidden group" } else { "hidden type layer" }; + assert_eq!(app.session.active().unwrap().active_layer, Some(text), "{what}: the type layer is the active one"); + let before = (past(&app), app.session.active().unwrap().doc.clone()); + drag_patch(&mut app); + assert!(prompt(&app).is_none(), "{what}: no prompt, the patch could never land there"); + assert!(app.ui.status_error, "{what}: the refusal stands: {}", app.ui.status); + assert!(patch_params(&app).is_empty(), "{what}"); + assert_eq!(past(&app), before.0, "{what}"); + assert_eq!(*app.session.active().unwrap().doc, *before.1, "{what}: the document is untouched"); + assert_eq!(active_content(&app), "Type", "{what} stays editable"); + } +} + +/// Review round: OK applies the patch to the layer the question was about. The params name no layer, +/// so a different layer that is active when OK comes must not take the pixels. +#[test] +fn ok_after_the_active_layer_changed_refuses_the_patch() { + let mut app = app("Type"); + let text = app.session.active().unwrap().active_layer.unwrap(); + drag_patch(&mut app); + let id = prompt(&app).expect("the prompt"); + // Another layer becomes the active one while the question is up. + let elsewhere = app.run("layer.new.layer", json!({"name": "Elsewhere"})).unwrap()["layer"].as_u64().unwrap(); + let before = past(&app); + answer(&mut app, id); + assert_eq!(app.session.active().unwrap().active_layer, Some(photocraft_doc::LayerId(elsewhere)), "the new layer is the active one"); + assert!(app.ui.status_error, "OK says why the patch did not run: {}", app.ui.status); + assert!(patch_params(&app).is_empty(), "the patch did not run on the layer that is active now"); + assert_eq!(past(&app), before + 1, "the layer the question was about is still rasterized"); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.layer(text).unwrap().content.kind_name(), "Pixel", "the stored layer took the rasterize"); +} + +/// Pin, passes before and after the change: a locked Type layer cannot be rasterized either, so the +/// drag keeps today's refusal and no prompt opens. +#[test] +fn a_locked_type_layer_still_refuses() { + let mut app = app("Type"); + app.run("layer.lockLayers", json!({"pixels": true})).unwrap(); + let before = (past(&app), app.session.active().unwrap().doc.clone()); + drag_patch(&mut app); + assert!(prompt(&app).is_none(), "a locked layer gets no prompt"); + assert!(app.ui.status_error, "the refusal stands: {}", app.ui.status); + assert!(patch_params(&app).is_empty()); + assert_eq!(past(&app), before.0); + assert_eq!(*app.session.active().unwrap().doc, *before.1, "the document is untouched"); + assert_eq!(active_content(&app), "Type"); +} + /// A pixel layer is unaffected: the patch applies with no question asked. #[test] fn a_pixel_layer_patch_still_applies_without_asking() { diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index e4441ec602..3bf6011d19 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -478,9 +478,12 @@ pub fn finish_patch(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) { let p = json!({"offset": off, "mode": app.ui.tool_options.patch_mode, "target": crate::canvas::paint_target(app)}); // #12121: on a Type layer the reference asks its rasterize question instead of refusing, and OK // applies this very patch on the layer it just rasterized. Only the measured case asks: the - // layer's own pixels in plain mode. Every other target and layer kind keeps the engine's refusal. + // layer's own pixels in plain mode, and only on a layer that is actually shown: the engine never + // writes to a hidden one, so a prompt there would let OK destroy the text for no patch. Every + // other target, hidden layer and layer kind keeps the engine's refusal. if let Some((kind, layer)) = crate::rasterize_prompt::needed(app) && kind == crate::rasterize_prompt::Kind::Type + && photocraft_engine::hidden_target::refusal(&app.session, "paint.patch", &p).is_none() { crate::rasterize_prompt::open_patch(app, kind, layer, p); return; From 13f14acf3bfc74c23352df44c5288da56f38df14 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Tue, 24 Nov 2026 06:54:10 +0100 Subject: [PATCH 3/4] fix(ui): keep the Patch rasterize answer inside its own document The prompt's tag names the layer by number, and a document read back from a file keeps the layer ids stored in it: `photocraft_format` preserves them on load and `Session::add_document` only re-picks the document id. Two open documents can therefore hold the same layer id. With the Patch question up and another document active, OK rasterized the Type layer carrying that id in the other document and, because that layer was the active one there, applied the replayed patch to it as well - pixels written in a document the question was never about. The tag now carries the document it was opened for, and the Patch answer refuses before anything is rasterized when that document is no longer the active one. The active-layer check that follows stays, so a different active layer inside the same document still refuses the patch alone. `ok_after_another_document_became_active_refuses_the_patch` (`crates/ui-egui/src/patch_rasterize_prompt_tests.rs`) opens a second document from the bytes of the first, so both hold the same Type layer id: red before this commit (no refusal, the second document took two history steps), green with it. --- .../ui-egui/src/dialogs/rasterize_prompt.rs | 29 +++++++++++++++---- .../src/patch_rasterize_prompt_tests.rs | 26 +++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt.rs b/crates/ui-egui/src/dialogs/rasterize_prompt.rs index 5f13fb2549..fef0a13252 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt.rs @@ -35,6 +35,10 @@ pub enum Kind { // Whether Convert is offered is fixed when the prompt opens (the button exists or not), so the tag does not carry it. pub(crate) struct Rasterize { kind: Kind, + /// The document `layer` was taken from. A document read back from a file keeps the layer ids + /// stored in it, so one number can name a layer of another open document; see + /// [`active_doc`]. + doc: u64, layer: u64, filter: Option<(String, Value)>, patch: Option, @@ -115,6 +119,14 @@ pub fn intercept(app: &mut PhotocraftApp, tool: Tool, x: f64, y: f64, pressure: true } +/// The document a prompt is opened for, as the id of the active document. The tag carries numbers, +/// and `Session::add_document` only re-picks a document id, so two documents read from files can hold +/// the same layer id (`photocraft_format` keeps the ids stored in a native file). `u64::MAX` means no +/// document: nothing matches it, so the answer refuses. +fn active_doc(app: &PhotocraftApp) -> u64 { + app.session.active().map_or(u64::MAX, |st| st.doc.id.0) +} + /// Opens the same question for a Patch drag on a `layer` that must be rasterized first: OK rasterizes /// it and then runs `paint.patch` with `params`, the params the finished drag had worked out, so the /// patch lands on the rasterized layer (#12121). Cancel does nothing. @@ -123,7 +135,7 @@ pub fn open_patch(app: &mut PhotocraftApp, kind: Kind, layer: photocraft_doc::La .title(tl!("PhotoCraft").to_owned()) .button(PromptChoice::Proceed, tl!("OK").to_owned()) .button(PromptChoice::Cancel, tl!("Cancel").to_owned()) - .tag(Rasterize { kind, layer: layer.0, filter: None, patch: Some(params) }); + .tag(Rasterize { kind, doc: active_doc(app), layer: layer.0, filter: None, patch: Some(params) }); alerts::open_prompt(app, prompt).unwrap_or_else(|open| open) } @@ -135,7 +147,7 @@ pub fn open(app: &mut PhotocraftApp, kind: Kind, layer: photocraft_doc::LayerId, .title(tl!("PhotoCraft").to_owned()) .button(PromptChoice::Proceed, tl!("OK").to_owned()) .button(PromptChoice::Cancel, tl!("Cancel").to_owned()) - .tag(Rasterize { kind, layer: layer.0, filter: None, patch: None }); + .tag(Rasterize { kind, doc: active_doc(app), layer: layer.0, filter: None, patch: None }); alerts::open_prompt(app, prompt).unwrap_or_else(|open| open) } @@ -178,6 +190,7 @@ pub fn intercept_filter(app: &mut PhotocraftApp, id: &str, params: &Value) -> Op } let prompt = prompt.button(PromptChoice::Cancel, tl!("Cancel").to_owned()).tag(Rasterize { kind: Kind::Type, + doc: active_doc(app), layer: layer.0, filter: Some((id.to_owned(), params.clone())), patch: None, @@ -191,11 +204,11 @@ pub fn intercept_filter(app: &mut PhotocraftApp, id: &str, params: &Value) -> Op /// that the layer can take it. A patch prompt's Proceed runs `paint.patch` on the layer it just /// rasterized (#12121). `false` for another family's answer. pub(crate) fn answer(app: &mut PhotocraftApp, ctx: &egui::Context, answer: &mut PromptAnswer) -> bool { - let Some(Rasterize { kind, layer, filter, patch }) = answer.take_tag::() else { return false }; + let Some(Rasterize { kind, doc, layer, filter, patch }) = answer.take_tag::() else { return false }; let result = match (answer.choice, filter, patch) { (PromptChoice::Proceed, None, None) => rasterize(app, kind, layer), // The Patch drag had already ended when this prompt opened, so its params re-run here. - (PromptChoice::Proceed, None, Some(params)) => rasterize_then_patch(app, kind, layer, params), + (PromptChoice::Proceed, None, Some(params)) => rasterize_then_patch(app, kind, doc, layer, params), (PromptChoice::Proceed | PromptChoice::Alternate, Some((filter, params)), None) => { convert_for_filter(app, ctx, answer.choice == PromptChoice::Alternate, &filter, params, layer) } @@ -223,7 +236,13 @@ fn rasterize(app: &mut PhotocraftApp, kind: Kind, layer: u64) -> Result Result { +fn rasterize_then_patch(app: &mut PhotocraftApp, kind: Kind, doc: u64, layer: u64, params: Value) -> Result { + // The layer id alone is not the target: a document read from a file keeps the layer ids stored in + // it, so another open document can hold that same number. Nothing is written when the active + // document is not the one the question was opened for (#12121). + if app.session.active().map(|st| st.doc.id.0) != Some(doc) { + return Err("the document this question was about is no longer the active document, so nothing was rasterized or patched".into()); + } let rasterized = rasterize(app, kind, layer)?; // The patch params name no layer: run as they stand, its pixels go to whatever is active when OK // comes. The rasterize above settled the layer the question was about, so a different active diff --git a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs index dc6b2ebca6..12ee6ff7ab 100644 --- a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs +++ b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs @@ -263,6 +263,32 @@ fn ok_after_the_active_layer_changed_refuses_the_patch() { assert_eq!(st.doc.layer(text).unwrap().content.kind_name(), "Pixel", "the stored layer took the rasterize"); } +/// Review round: a document read from a file keeps the layer ids stored in it, so two open +/// documents can hold the same number. OK must not rasterize or patch in another document than the +/// one the question was opened for. +#[test] +fn ok_after_another_document_became_active_refuses_the_patch() { + let mut app = app("Type"); + let text = app.session.active().unwrap().active_layer.unwrap(); + drag_patch(&mut app); + let id = prompt(&app).expect("the prompt"); + // A second document made from this one's bytes: its layers keep the ids stored in the file, so + // the same number names a Type layer there too, and that layer is the active one there. + let bytes = photocraft_format::save_to_bytes(&app.session.active().unwrap().doc, &Default::default()).unwrap(); + let twin = photocraft_format::load_from_bytes(&bytes).unwrap(); + assert_eq!(twin.layer(text).map(|l| l.content.kind_name()), Some("Type"), "both documents hold a Type layer {}", text.0); + app.session.add_document(twin, None); + let st = app.session.active().unwrap(); + assert_eq!(st.active_layer, Some(text), "the other document's active layer carries the same id"); + let revision = st.revision; + let first = app.session.documents()[0].doc.clone(); + answer(&mut app, id); + assert!(app.ui.status_error, "OK says why nothing ran: {}", app.ui.status); + assert!(patch_params(&app).is_empty(), "no patch ran in the other document"); + assert_eq!(app.session.active().unwrap().revision, revision, "the other document is untouched"); + assert_eq!(first.layer(text).unwrap().content.kind_name(), "Type", "the document the question was about keeps its text"); +} + /// Pin, passes before and after the change: a locked Type layer cannot be rasterized either, so the /// drag keeps today's refusal and no prompt opens. #[test] From 462d6c7f986705a5755452659b69d97a7ee45765 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Tue, 24 Nov 2026 08:07:32 +0100 Subject: [PATCH 4/4] fix(ui): keep every rasterize answer inside its own document The Patch guard closed one path of a hole the whole prompt family shares: the tag names its layer by number, and a document read back from a file keeps the layer ids stored in it, so the same number can name a layer of another open document. A brush press in one document, answered while another document has become active, rasterized that document's same-id layer; the Filter menu's prompt converted or rasterized it there and ran its filter on it. The refusal now lives in one `stale_document` helper that `rasterize` and `convert_for_filter` answer with, and `rasterize_then_patch` runs through it, so no family writes into a document the question was not opened for. The patch's own active-layer check stays, so a different active layer inside the same document still refuses the patch alone. Red at 13f14acf3, green now: `a_document_switch_while_the_prompt_is_up_rasterizes_nothing` (brush press, second document made from the first one's bytes: before this commit that document's Type layer lost its text and took the history step) and `the_filter_prompt_refuses_a_document_that_is_no_longer_active` (Gaussian Blur asked on one document, answered with another active: before, it rasterized the other document's layer and opened its filter dialog). `ok_after_another_document_became_active_refuses_the_patch` read a copy of the first document taken before the answer, an assert that could not fail; it now reads both documents after the answer. --- .../ui-egui/src/dialogs/rasterize_prompt.rs | 37 ++++++++----- .../src/dialogs/rasterize_prompt/tests.rs | 55 +++++++++++++++++++ .../src/patch_rasterize_prompt_tests.rs | 17 ++++-- 3 files changed, 90 insertions(+), 19 deletions(-) diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt.rs b/crates/ui-egui/src/dialogs/rasterize_prompt.rs index fef0a13252..8b8236d4a9 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt.rs @@ -122,11 +122,19 @@ pub fn intercept(app: &mut PhotocraftApp, tool: Tool, x: f64, y: f64, pressure: /// The document a prompt is opened for, as the id of the active document. The tag carries numbers, /// and `Session::add_document` only re-picks a document id, so two documents read from files can hold /// the same layer id (`photocraft_format` keeps the ids stored in a native file). `u64::MAX` means no -/// document: nothing matches it, so the answer refuses. +/// document: nothing matches it, so the answer refuses. See [`stale_document`]. fn active_doc(app: &PhotocraftApp) -> u64 { app.session.active().map_or(u64::MAX, |st| st.doc.id.0) } +/// The refusal the writing answers share. The tag names its target by number, and a document read +/// back from a file keeps the layer ids stored in it, so that number can name a layer of another +/// open document: when the active document is not the one the question was opened for, the answer +/// writes in neither of them (#12121). +fn stale_document(app: &PhotocraftApp, doc: u64) -> Option { + (active_doc(app) != doc).then(|| "the document this question was about is no longer the active document, so nothing was rasterized".to_owned()) +} + /// Opens the same question for a Patch drag on a `layer` that must be rasterized first: OK rasterizes /// it and then runs `paint.patch` with `params`, the params the finished drag had worked out, so the /// patch lands on the rasterized layer (#12121). Cancel does nothing. @@ -202,15 +210,16 @@ pub fn intercept_filter(app: &mut PhotocraftApp, id: &str, params: &Value) -> Op /// The `PROMPTS` entry: Proceed rasterizes, Alternate converts to a Smart Object (the filter prompt /// only), Cancel does nothing. The filter of a filter prompt runs at once, as the menu would, now /// that the layer can take it. A patch prompt's Proceed runs `paint.patch` on the layer it just -/// rasterized (#12121). `false` for another family's answer. +/// rasterized (#12121). Every answer that writes first refuses when the active document is not the +/// one the question was opened for ([`stale_document`]). `false` for another family's answer. pub(crate) fn answer(app: &mut PhotocraftApp, ctx: &egui::Context, answer: &mut PromptAnswer) -> bool { let Some(Rasterize { kind, doc, layer, filter, patch }) = answer.take_tag::() else { return false }; let result = match (answer.choice, filter, patch) { - (PromptChoice::Proceed, None, None) => rasterize(app, kind, layer), + (PromptChoice::Proceed, None, None) => rasterize(app, kind, doc, layer), // The Patch drag had already ended when this prompt opened, so its params re-run here. (PromptChoice::Proceed, None, Some(params)) => rasterize_then_patch(app, kind, doc, layer, params), (PromptChoice::Proceed | PromptChoice::Alternate, Some((filter, params)), None) => { - convert_for_filter(app, ctx, answer.choice == PromptChoice::Alternate, &filter, params, layer) + convert_for_filter(app, ctx, answer.choice == PromptChoice::Alternate, &filter, params, doc, layer) } _ => return true, }; @@ -219,7 +228,10 @@ pub(crate) fn answer(app: &mut PhotocraftApp, ctx: &egui::Context, answer: &mut } /// OK: rasterize the layer. The click that opened the prompt does not paint. -fn rasterize(app: &mut PhotocraftApp, kind: Kind, layer: u64) -> Result { +fn rasterize(app: &mut PhotocraftApp, kind: Kind, doc: u64, layer: u64) -> Result { + if let Some(why) = stale_document(app, doc) { + return Err(why); + } let revision = app.session.active().map(|st| st.revision); let r = app.run(kind.command(), json!({ "layer": layer }))?; // A painting tool's type prompt names its step as the reference does (#12888); Layer › @@ -237,13 +249,9 @@ fn rasterize(app: &mut PhotocraftApp, kind: Kind, layer: u64) -> Result Result { - // The layer id alone is not the target: a document read from a file keeps the layer ids stored in - // it, so another open document can hold that same number. Nothing is written when the active - // document is not the one the question was opened for (#12121). - if app.session.active().map(|st| st.doc.id.0) != Some(doc) { - return Err("the document this question was about is no longer the active document, so nothing was rasterized or patched".into()); - } - let rasterized = rasterize(app, kind, layer)?; + // `rasterize` answers for the document the question was opened for, so a patch can never follow + // it into another document whose layers happen to carry the same ids (#12121). + let rasterized = rasterize(app, kind, doc, layer)?; // The patch params name no layer: run as they stand, its pixels go to whatever is active when OK // comes. The rasterize above settled the layer the question was about, so a different active // layer now refuses the patch instead of painting somewhere else (#12121). @@ -255,7 +263,10 @@ fn rasterize_then_patch(app: &mut PhotocraftApp, kind: Kind, doc: u64, layer: u6 } /// The filter prompt's answer: convert (`smart`) or rasterize the layer, then run the filter. -fn convert_for_filter(app: &mut PhotocraftApp, ctx: &egui::Context, smart: bool, filter: &str, params: Value, layer: u64) -> Result { +fn convert_for_filter(app: &mut PhotocraftApp, ctx: &egui::Context, smart: bool, filter: &str, params: Value, doc: u64, layer: u64) -> Result { + if let Some(why) = stale_document(app, doc) { + return Err(why); + } let command = if smart { "layer.smartObjects.convertToSmartObject" } else { Kind::Type.command() }; let converted = app.run(command, json!({ "layer": layer }))?; crate::menus::invoke(app, ctx, filter, params)?; diff --git a/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs b/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs index 51ba8c87ea..176bcc374f 100644 --- a/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs +++ b/crates/ui-egui/src/dialogs/rasterize_prompt/tests.rs @@ -183,6 +183,61 @@ fn a_stale_prompt_fails_gracefully() { assert_eq!(past(&app), before); } +/// Review round: the prompt names its layer by number, and a document read back from a file keeps the +/// layer ids stored in it, so two open documents can hold the same number. A brush press in one +/// document whose question is answered while another document is active writes in neither of them. +#[test] +fn a_document_switch_while_the_prompt_is_up_rasterizes_nothing() { + let mut app = app_with(Kind::Type); + app.ui.tool = Tool::Brush; + let mine = app.session.active_index().unwrap(); + let text = app.session.active().unwrap().active_layer.unwrap(); + click(&mut app, 30.0, 20.0); + let id = prompt(&app).expect("the press opened the prompt"); + // A second document made from the bytes of the first: its layers keep the ids stored in the file, + // so the same number names a Type layer there too, and that layer is active there. + let bytes = photocraft_format::save_to_bytes(&app.session.active().unwrap().doc, &Default::default()).unwrap(); + let twin = photocraft_format::load_from_bytes(&bytes).unwrap(); + assert_eq!(twin.layer(text).map(|l| l.content.kind_name()), Some("Type"), "both documents hold a Type layer {}", text.0); + app.session.add_document(twin, None); + let other = app.session.active_index().unwrap(); + assert_ne!(other, mine, "the second document is the active one now"); + assert_eq!(app.session.documents()[other].active_layer, Some(text), "the other document's active layer carries the same id"); + let (before_other, before_mine) = (app.session.documents()[other].revision, app.session.documents()[mine].revision); + answer(&mut app, id); + assert!(app.ui.status_error, "OK says why nothing ran: {}", app.ui.status); + // Both documents are read live, after the answer. + assert_eq!(app.session.documents()[other].revision, before_other, "no history step in the document that is active now"); + assert_eq!(app.session.documents()[other].doc.layer(text).unwrap().content.kind_name(), "Type", "its Type layer stays editable"); + assert_eq!(app.session.documents()[mine].revision, before_mine, "the document the question was about is untouched"); + assert_eq!(app.session.documents()[mine].doc.layer(text).unwrap().content.kind_name(), "Type", "and keeps its text"); +} + +/// The Filter menu's prompt keeps its question inside the document it was opened for for the same +/// reason: OK would otherwise rasterize or convert a same-id layer of another open document and run +/// the filter on that one. +#[test] +fn the_filter_prompt_refuses_a_document_that_is_no_longer_active() { + let mut app = app_with(Kind::Type); + let mine = app.session.active_index().unwrap(); + let text = app.session.active().unwrap().active_layer.unwrap(); + menu(&mut app, BLUR).unwrap(); + let id = prompt(&app).expect("the filter asks first"); + let bytes = photocraft_format::save_to_bytes(&app.session.active().unwrap().doc, &Default::default()).unwrap(); + let twin = photocraft_format::load_from_bytes(&bytes).unwrap(); + assert_eq!(twin.layer(text).map(|l| l.content.kind_name()), Some("Type"), "both documents hold a Type layer {}", text.0); + app.session.add_document(twin, None); + let other = app.session.active_index().unwrap(); + let (before_other, before_mine) = (app.session.documents()[other].revision, app.session.documents()[mine].revision); + answer(&mut app, id); + assert!(app.ui.status_error, "OK says why nothing ran: {}", app.ui.status); + assert_eq!(app.session.documents()[other].revision, before_other, "no history step in the document that is active now"); + assert_eq!(app.session.documents()[other].doc.layer(text).unwrap().content.kind_name(), "Type", "its Type layer stays editable"); + assert!(filter_dialog(&app, BLUR).is_none(), "Gaussian Blur did not open on the other document"); + assert_eq!(app.session.documents()[mine].revision, before_mine, "the document the question was about is untouched"); + assert_eq!(app.session.documents()[mine].doc.layer(text).unwrap().content.kind_name(), "Type", "and keeps its text"); +} + #[test] fn the_control_channel_sees_and_confirms_the_prompt() { let mut app = app_with(Kind::Shape); diff --git a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs index 12ee6ff7ab..71819b1b6b 100644 --- a/crates/ui-egui/src/patch_rasterize_prompt_tests.rs +++ b/crates/ui-egui/src/patch_rasterize_prompt_tests.rs @@ -270,6 +270,7 @@ fn ok_after_the_active_layer_changed_refuses_the_patch() { fn ok_after_another_document_became_active_refuses_the_patch() { let mut app = app("Type"); let text = app.session.active().unwrap().active_layer.unwrap(); + let mine = app.session.active_index().unwrap(); drag_patch(&mut app); let id = prompt(&app).expect("the prompt"); // A second document made from this one's bytes: its layers keep the ids stored in the file, so @@ -278,15 +279,19 @@ fn ok_after_another_document_became_active_refuses_the_patch() { let twin = photocraft_format::load_from_bytes(&bytes).unwrap(); assert_eq!(twin.layer(text).map(|l| l.content.kind_name()), Some("Type"), "both documents hold a Type layer {}", text.0); app.session.add_document(twin, None); - let st = app.session.active().unwrap(); - assert_eq!(st.active_layer, Some(text), "the other document's active layer carries the same id"); - let revision = st.revision; - let first = app.session.documents()[0].doc.clone(); + let other = app.session.active_index().unwrap(); + assert_ne!(other, mine, "the second document is the active one now"); + assert_eq!(app.session.documents()[other].active_layer, Some(text), "the other document's active layer carries the same id"); + let (before_other, before_mine) = (app.session.documents()[other].revision, app.session.documents()[mine].revision); answer(&mut app, id); assert!(app.ui.status_error, "OK says why nothing ran: {}", app.ui.status); assert!(patch_params(&app).is_empty(), "no patch ran in the other document"); - assert_eq!(app.session.active().unwrap().revision, revision, "the other document is untouched"); - assert_eq!(first.layer(text).unwrap().content.kind_name(), "Type", "the document the question was about keeps its text"); + // Read both documents live, after the answer: a copy taken before it would show the old document + // however much the answer changed it. + assert_eq!(app.session.documents()[other].revision, before_other, "the other document is untouched"); + assert_eq!(app.session.documents()[other].doc.layer(text).unwrap().content.kind_name(), "Type", "the other document keeps its text"); + assert_eq!(app.session.documents()[mine].revision, before_mine, "the document the question was about is untouched too"); + assert_eq!(app.session.documents()[mine].doc.layer(text).unwrap().content.kind_name(), "Type", "and keeps its text"); } /// Pin, passes before and after the change: a locked Type layer cannot be rasterized either, so the