From ba9065fcfce0e96b6202ea9559584a43f013e7fd Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:41:50 +0100 Subject: [PATCH 1/3] Free Transform: grey Warp for a group box (#16731) A box over a group now opens with warp off, as the box over several layers does: Warp is greyed in its right-click menu and Edit > Transform > Warp (with the split-warp rows) is greyed while it is open. Warp asked through automation, or from the menu with no box open, refuses on a group instead of opening a plain box. Pixel, type and smart object layers keep Warp. --- .../ui-egui/src/tools/transform_tool/begin.rs | 28 +++++++-- .../src/tools/transform_tool/commit.rs | 6 +- .../transform_tool/group_warp_greyed_tests.rs | 58 +++++++++++++++++++ .../ui-egui/src/tools/transform_tool/tests.rs | 3 + 4 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs diff --git a/crates/ui-egui/src/tools/transform_tool/begin.rs b/crates/ui-egui/src/tools/transform_tool/begin.rs index c90ea547e7..0756c0cfff 100644 --- a/crates/ui-egui/src/tools/transform_tool/begin.rs +++ b/crates/ui-egui/src/tools/transform_tool/begin.rs @@ -24,7 +24,7 @@ fn type_allow(typed: bool) -> BoxAllow { } /// The session over the source frame `rect`: the stored settings, the interpolation default and the nudge pause. -/// `warp_ok` is false where the content cannot warp (a lone mask or channel, several layers, Content-Aware Scale). +/// `warp_ok` is false where the content cannot warp (a lone mask or channel, several layers, a group, Content-Aware Scale). fn open_session(app: &PhotocraftApp, rect: [f64; 4], allow: BoxAllow, warp_ok: bool) -> TransformSession { TransformSession::new(frame_of(rect)) .allow(allow.with_warp(warp_ok)) @@ -130,6 +130,8 @@ pub fn begin(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> let opacity = layer.opacity * layer.fill_opacity; let whole = lifted.is_none(); let allow = type_allow(matches!(layer.content, LayerContent::Text(_))); + // A group doesn't warp, as several layers don't (#16731). + let warp_ok = !frame_only && !matches!(layer.content, LayerContent::Group(_)); // Reading the moving pixels and compositing the layers over them is the heavy part: hundreds // of megapixels on a large canvas. Done on the UI thread, the window stopped answering for // long enough that a Wayland compositor dropped it, so a large layer prepares as a job @@ -161,7 +163,7 @@ pub fn begin(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> ..OpenPreview::new(session, shown, textures, app.ui.tool) }); app.ui.transform = Some(FreeTransform { - session: open_session(app, rect, allow, !frame_only), + session: open_session(app, rect, allow, warp_ok), id: session, layer: id.0, layers: Vec::new(), @@ -373,9 +375,23 @@ pub(super) fn moves_kind(app: &PhotocraftApp, t: &FreeTransform, kind: fn(&Layer app.session.active().is_some_and(|st| moving_layers(t).iter().any(|id| st.doc.layer(*id).is_some_and(|l| kind(&l.content)))) } +/// Does the box move a group as one layer (not its mask, a path or a selection outline)? +pub(super) fn moves_group(app: &PhotocraftApp, t: &FreeTransform) -> bool { + t.layers.is_empty() && !t.selection && t.target.is_none() && t.path.is_none() && moves_kind(app, t, |c| matches!(c, LayerContent::Group(_))) +} + /// Why Warp refuses with several layers selected. pub const WARP_ONE_LAYER: &str = "Warp works on one layer at a time: select a single layer"; +/// Why Warp refuses on a group (#16731). +pub const WARP_GROUP: &str = "Warp doesn't work on a group"; + +/// Why the open box can't warp: several layers (#6501) or a group (#16731). +fn warp_refusal(app: &PhotocraftApp) -> Option<&'static str> { + let t = app.ui.transform.as_ref()?; + if !t.layers.is_empty() { Some(WARP_ONE_LAYER) } else { moves_group(app, t).then_some(WARP_GROUP) } +} + /// Free Transform on a copy (⌥⌘T, no menu item): duplicates the active layer (with a selection, /// its selected pixels, as Layer via Copy) and transforms the copy (#352). pub fn begin_copy(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> { @@ -688,14 +704,14 @@ pub fn begin_warp(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), St if app.ui.transform.as_ref().is_some_and(|t| t.content_aware.is_some()) { return Err(CAS_ONLY_SCALES.into()); } - if app.ui.transform.as_ref().is_some_and(|t| !t.layers.is_empty()) { - return Err(WARP_ONE_LAYER.into()); + if let Some(why) = warp_refusal(app) { + return Err(why.into()); } if app.ui.transform.is_none() { begin(app, ctx)?; - if app.ui.transform.as_ref().is_some_and(|t| !t.layers.is_empty()) { + if let Some(why) = warp_refusal(app) { cancel(app); - return Err(WARP_ONE_LAYER.into()); + return Err(why.into()); } } enter_warp(app, ctx); diff --git a/crates/ui-egui/src/tools/transform_tool/commit.rs b/crates/ui-egui/src/tools/transform_tool/commit.rs index 8dc1166dcb..7829c4c3af 100644 --- a/crates/ui-egui/src/tools/transform_tool/commit.rs +++ b/crates/ui-egui/src/tools/transform_tool/commit.rs @@ -2,7 +2,7 @@ use craft::behavior::EditEvent; use craft::behavior::kurbo::Point; use craft::draw::ui::transform::{TransformEdit, TransformRequest}; -use super::begin::{fold_made, moves_kind, moving_layers, rect_to_quad_affine, take_back_made}; +use super::begin::{fold_made, moves_group, moves_kind, moving_layers, rect_to_quad_affine, take_back_made}; use super::{ Arc, DocId, FreeTransform, JobEvent, JobId, JobOutcome, LayerContent, LayerId, MadeLayer, OpenPreview, PhotocraftApp, SessionWarp, Several, json, preset_for_command, swap_mode_texels, @@ -414,14 +414,14 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option { SAVE_FOR_WEB | COPY_CSS => Some(false), // Rotate and Flip turn the box (not while warping, where the mesh is the box). _ if preset_for_command(id).is_some() => Some(t.session.warp().is_none()), - // One box over several layers doesn't warp (#6501). + // One box over several layers doesn't warp (#6501), nor one over a group (#16731). "edit.transform.warp" | "layer.smartObjects.warp" | "edit.transform.splitWarpCrosswise" | "edit.transform.splitWarpHorizontally" | "edit.transform.splitWarpVertically" | "edit.transform.removeWarpSplit" - if !t.layers.is_empty() => + if !t.layers.is_empty() || moves_group(app, t) => { Some(false) } diff --git a/crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs b/crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs new file mode 100644 index 0000000000..70cc70293f --- /dev/null +++ b/crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs @@ -0,0 +1,58 @@ +//! #16731: a box over a group doesn't warp, as one over several layers doesn't; a box over one +//! layer of any other kind still does. + +use super::*; +use crate::transform_tool::begin::WARP_GROUP; + +/// The Edit › Transform rows of the Warp block. +const WARP_BLOCK: [&str; 5] = [ + "edit.transform.warp", + "edit.transform.splitWarpCrosswise", + "edit.transform.splitWarpHorizontally", + "edit.transform.splitWarpVertically", + "edit.transform.removeWarpSplit", +]; + +/// Is the Warp row of the open box's right-click menu enabled? +fn warp_row(app: &PhotocraftApp) -> bool { + let words = TransformMenuWords::english(); + open(app).session.menu(&words).iter().find(|e| matches!(e.value(), Some(TransformChoice::Warp))).map(|e| e.is_enabled()).expect("the menu has a Warp row") +} + +#[test] +fn a_group_box_greys_warp_in_its_menu_and_in_edit_transform() { + let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + let ctx = app.ctx().clone(); + app.session.execute("layer.new.groupFromLayers", json!({})).unwrap(); + let st = app.session.active().unwrap(); + assert!(st.active_layer.and_then(|id| st.doc.layer(id)).is_some_and(|l| matches!(l.content, LayerContent::Group(_))), "the group is active"); + begin(&mut app, &ctx).unwrap(); + assert!(open(&app).layers.is_empty(), "a box over the group as one layer"); + assert!(!warp_row(&app), "Warp is greyed in the box's menu"); + for id in WARP_BLOCK { + assert!(!crate::menus::is_enabled(&app, id), "{id} is greyed while the group box is open"); + } + // Asked anyway (automation), Warp refuses and leaves the box as it was. + assert_eq!(begin_warp(&mut app, &ctx), Err(WARP_GROUP.into())); + assert!(open(&app).session.warp().is_none(), "the box doesn't switch to Warp"); + cancel(&mut app); + // With no box open, Warp refuses without leaving one behind. + assert_eq!(begin_warp(&mut app, &ctx), Err(WARP_GROUP.into())); + assert!(app.ui.transform.is_none(), "no box is left open"); +} + +#[test] +fn single_pixel_type_and_smart_object_layers_keep_warp() { + let ctx = egui::Context::default(); + let pixel = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + let mut typed = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + typed.run("type.create", json!({"x": 10, "y": 40, "text": "Hi"})).unwrap(); + let mut smart = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + smart.session.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + for (name, mut app) in [("pixel", pixel), ("type", typed), ("smart object", smart)] { + begin(&mut app, &ctx).unwrap(); + assert!(warp_row(&app), "a {name} layer's box offers Warp"); + assert!(crate::menus::is_enabled(&app, "edit.transform.warp"), "Edit › Transform › Warp is live over a {name} layer"); + cancel(&mut app); + } +} diff --git a/crates/ui-egui/src/tools/transform_tool/tests.rs b/crates/ui-egui/src/tools/transform_tool/tests.rs index 1a6a44c965..a445c57098 100644 --- a/crates/ui-egui/src/tools/transform_tool/tests.rs +++ b/crates/ui-egui/src/tools/transform_tool/tests.rs @@ -2219,3 +2219,6 @@ fn an_unskewed_box_shows_its_horizontal_skew_as_zero() { #[path = "warp_remove_split_tests.rs"] mod warp_remove_split_tests; + +#[path = "group_warp_greyed_tests.rs"] +mod group_warp_greyed_tests; From c5b500f40a54f0bc21c52207f85d07763645c7af Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:46:08 +0100 Subject: [PATCH 2/3] Layers: thumbnail gestures get the reference application's history names (#16786) Thumbnail Ctrl+click and Select Pixels are Load Selection (Selection Change for a shape or a vector mask), Shift+click and the chain name their direction, and a mask drop is one Add Layer Mask step. The menu calls (no layer id, plain toggles) keep their names. --- .../src/cmd/channel_cmds/selection.rs | 23 +++- crates/engine-core/src/cmd/extra_cmds.rs | 11 +- crates/engine-core/src/cmd/ops.rs | 6 +- .../src/cmd/vector_cmds/vector_mask.rs | 18 ++- .../it/layers_thumbnail_history_names.rs | 110 ++++++++++++++++++ crates/engine/tests/it/main.rs | 1 + 6 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 crates/engine/tests/it/layers_thumbnail_history_names.rs diff --git a/crates/engine-core/src/cmd/channel_cmds/selection.rs b/crates/engine-core/src/cmd/channel_cmds/selection.rs index a49c551d2f..f5b1dc3f30 100644 --- a/crates/engine-core/src/cmd/channel_cmds/selection.rs +++ b/crates/engine-core/src/cmd/channel_cmds/selection.rs @@ -60,6 +60,23 @@ pub(super) fn save_selection(s: &mut Session, p: &Value) -> Result { Ok(json!({ "channel": i, "name": name, "document": di })) } +/// The history name of `select.loadSelection` with `p`. The Layers panel names its layer by id (a thumbnail +/// ⌘-click, Select Pixels), and those loads take Photoshop's names (#16786): `Selection Change` for a shape's +/// path or a vector mask, `Load Selection` for another layer's transparency or a layer mask. Calls that don't +/// name a layer by id (Select › Load Selection) keep their names. +fn load_label(doc: &Document, p: &Value) -> &'static str { + let channel = p.get("channel").and_then(|v| parse_ref(v, doc)); + let layer = p.get("layer").and_then(Value::as_u64).and_then(|id| doc.layer(super::LayerId(id))); + match (channel, layer) { + (Some(ChanRef::Transparency), Some(l)) if matches!(l.content, super::LayerContent::Shape(_)) => "Selection Change", + (Some(ChanRef::Transparency), Some(l)) if !l.is_group() => "Load Selection", + (Some(ChanRef::VectorMask), Some(l)) if l.vector_mask.is_some() => "Selection Change", + (Some(ChanRef::Transparency), _) => "Load Transparency", + (Some(ChanRef::LayerMask), None) => "Load Layer Mask", + _ => "Load Selection", + } +} + pub(super) fn load_selection(s: &mut Session, p: &Value) -> Result { let cmd = "select.loadSelection"; let mode = match operation(p, "operation") { @@ -89,11 +106,7 @@ pub(super) fn load_selection(s: &mut Session, p: &Value) -> Result { // Composite and colour channels load their luminosity / values, as ⌘-clicking them does. let plane = source(s, p, cmd, true)?.into_iter().next().ok_or_else(|| bad(cmd, "the channel has no pixels"))?; let doc = &s.active().ok_or(EngineError::NoDocument)?.doc; - let label = match p.get("channel").and_then(|v| parse_ref(v, doc)) { - Some(ChanRef::Transparency) => "Load Transparency", - Some(ChanRef::LayerMask) => "Load Layer Mask", - _ => "Load Selection", - }; + let label = load_label(doc, p); let selected = s.edit(label, |doc, _| { doc.selection = sel::combine(doc.selection.as_ref(), &plane, doc.bounds(), mode); Ok(doc.selection.is_some()) diff --git a/crates/engine-core/src/cmd/extra_cmds.rs b/crates/engine-core/src/cmd/extra_cmds.rs index aadcfc89ca..6aa06a7c00 100644 --- a/crates/engine-core/src/cmd/extra_cmds.rs +++ b/crates/engine-core/src/cmd/extra_cmds.rs @@ -550,7 +550,16 @@ pub fn background_to_layer(doc: &mut photocraft_doc::Document, id: photocraft_do fn toggle_mask(s: &mut Session, p: &Value, key: &str) -> Result { let id = layer_param(s, p)?; - let label = if key == "enabled" { "Enable/Disable Layer Mask" } else { "Link/Unlink Layer Mask" }; + // A call that says the direction (the Layers panel's ⇧-click and chain) is named by it, as in Photoshop + // (#16786); a plain toggle (Layer › Layer Mask) keeps its two-way name. + let label = match (key, p.get(key).and_then(Value::as_bool)) { + ("enabled", Some(true)) => "Enable Layer Mask", + ("enabled", Some(false)) => "Disable Layer Mask", + ("enabled", None) => "Enable/Disable Layer Mask", + (_, Some(true)) => "Link Mask", + (_, Some(false)) => "Unlink Mask", + (_, None) => "Link/Unlink Layer Mask", + }; let v = s.edit(label, |doc, _| { let m = doc.layer_mut(id).and_then(|l| l.mask.as_mut()).ok_or(EngineError::Other("the layer has no layer mask".into()))?; let slot = if key == "enabled" { &mut m.enabled } else { &mut m.linked }; diff --git a/crates/engine-core/src/cmd/ops.rs b/crates/engine-core/src/cmd/ops.rs index 7e08493d68..e892c43325 100644 --- a/crates/engine-core/src/cmd/ops.rs +++ b/crates/engine-core/src/cmd/ops.rs @@ -99,7 +99,8 @@ fn set_mask_with(s: &mut Session, p: &Value, label: &str, mask: Option Result { let bad = |m: &str| EngineError::BadParams { cmd: "layer.layerMask.moveTo".into(), msg: m.into() }; let from = layer_param(s, p)?; @@ -109,8 +110,7 @@ pub(super) fn move_mask(s: &mut Session, p: &Value) -> Result { if from == to { return Err(bad("the mask is already on that layer")); } - let label = if copy { "Copy Layer Mask" } else { "Move Layer Mask" }; - s.edit(label, |doc, _| { + s.edit("Add Layer Mask", |doc, _| { let mask = doc.layer(from).ok_or(EngineError::NoLayer(from))?.mask.clone().ok_or_else(|| bad("the layer has no layer mask"))?; if doc.layer(to).ok_or(EngineError::NoLayer(to))?.mask.is_some() && !replace { return Err(bad("the layer already has a layer mask (pass `replace`)")); diff --git a/crates/engine-core/src/cmd/vector_cmds/vector_mask.rs b/crates/engine-core/src/cmd/vector_cmds/vector_mask.rs index 34abf1eab0..a03de7ff50 100644 --- a/crates/engine-core/src/cmd/vector_cmds/vector_mask.rs +++ b/crates/engine-core/src/cmd/vector_cmds/vector_mask.rs @@ -58,6 +58,11 @@ pub(super) fn vector_mask_add(s: &mut Session, p: &Value, from_path: bool) -> Re } pub(super) fn vector_mask_edit(s: &mut Session, p: &Value) -> Result { + edit_vector_mask(s, p, "Edit Vector Mask") +} + +/// `layer.vectorMask.edit` with `p`, its history step named `label`. +fn edit_vector_mask(s: &mut Session, p: &Value, label: &str) -> Result { const CMD: &str = "layer.vectorMask.edit"; let id = layer_id(s, p)?; let path = p.get("path").map(parse_path).transpose().map_err(|e| bad(CMD, e))?; @@ -100,7 +105,7 @@ pub(super) fn vector_mask_edit(s: &mut Session, p: &Value) -> Result { })?; return vector_mask_info(s, id); } - s.edit("Edit Vector Mask", |doc, _| { + s.edit(label, |doc, _| { let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?; let vm = l.vector_mask.as_mut().ok_or_else(|| EngineError::Other("layer has no vector mask".into()))?; if let Some(pth) = path { @@ -194,6 +199,15 @@ pub(super) fn toggle_vector_mask(s: &mut Session, p: &Value, key: &str) -> Resul let vm = d.doc.layer(id).ok_or(EngineError::NoLayer(id))?.vector_mask.as_ref().ok_or_else(|| EngineError::Other("layer has no vector mask".into()))?; if key == "enabled" { vm.enabled } else { vm.linked } }; + // A call that says the direction (the Layers panel's ⇧-click and chain) is named by it, as in Photoshop + // (#16786); a plain toggle (Layer › Vector Mask) keeps its name. + let label = match (key, p.get(key).and_then(Value::as_bool)) { + ("enabled", Some(true)) => "Enable Vector Mask", + ("enabled", Some(false)) => "Disable Vector Mask", + (_, Some(true)) => "Link Vector Mask", + (_, Some(false)) => "Unlink Vector Mask", + (_, None) => "Edit Vector Mask", + }; let v = p.get(key).and_then(Value::as_bool).unwrap_or(!cur); - vector_mask_edit(s, &json!({ "layer": id.0, key: v })) + edit_vector_mask(s, &json!({ "layer": id.0, key: v }), label) } diff --git a/crates/engine/tests/it/layers_thumbnail_history_names.rs b/crates/engine/tests/it/layers_thumbnail_history_names.rs new file mode 100644 index 0000000000..948f51158d --- /dev/null +++ b/crates/engine/tests/it/layers_thumbnail_history_names.rs @@ -0,0 +1,110 @@ +//! History names of the Layers panel's thumbnail gestures (#16786), run with the params the panel sends, and the +//! Layer and Select menus' calls of the same commands, which keep their names. + +use photocraft_engine::Session; +use serde_json::{Value, json}; + +fn session() -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); + s +} + +fn active(s: &Session) -> u64 { + s.active().unwrap().active_layer.unwrap().0 +} + +/// A new pixel layer filled with red, active. +fn pixel_layer(s: &mut Session) -> u64 { + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); + active(s) +} + +/// The name of the one history state `cmd` with `params` adds. +fn step(s: &mut Session, cmd: &str, params: Value) -> String { + let before = s.active().unwrap().history.entries().len(); + s.execute(cmd, params.clone()).unwrap_or_else(|e| panic!("{cmd} {params}: {e}")); + let after = s.active().unwrap().history.entries(); + assert_eq!(after.len(), before + 1, "{cmd} {params} adds one state: {after:?}"); + after[before].clone() +} + +/// ⌘-click (with ⇧ / ⌥ too) on a pixel, type, smart object or adjustment thumbnail, Select Pixels and ⌘-click on a +/// layer mask are `Load Selection`; on a shape thumbnail or a vector mask, `Selection Change`. +#[test] +fn thumbnail_loads_are_named_as_their_kind() { + let mut s = session(); + let pixel = pixel_layer(&mut s); + pixel_layer(&mut s); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = active(&s); + let typ = s.execute("type.create", json!({"text": "A", "x": 5, "y": 20})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); + let adjustment = active(&s); + for layer in [pixel, smart, typ, adjustment] { + for operation in ["new", "add", "subtract", "intersect"] { + let params = json!({"channel": "transparency", "layer": layer, "operation": operation}); + assert_eq!(step(&mut s, "select.loadSelection", params), "Load Selection", "layer {layer}, {operation}"); + } + } + s.execute("layer.layerMask.revealAll", json!({"layer": pixel})).unwrap(); + assert_eq!(step(&mut s, "select.loadSelection", json!({"channel": "mask", "layer": pixel, "operation": "new"})), "Load Selection"); + + let shape = s.execute("shape.create", json!({"kind": "rect", "rect": [2, 2, 20, 20]})).unwrap()["layer"].as_u64().unwrap(); + let params = json!({"channel": "transparency", "layer": shape, "operation": "new"}); + assert_eq!(step(&mut s, "select.loadSelection", params), "Selection Change", "shape thumbnail"); + s.execute("layer.vectorMask.revealAll", json!({"layer": pixel})).unwrap(); + let params = json!({"channel": "vectorMask", "layer": pixel, "operation": "add"}); + assert_eq!(step(&mut s, "select.loadSelection", params), "Selection Change", "vector mask"); +} + +/// Select › Load Selection names no layer, and keeps its names. +#[test] +fn the_menu_load_keeps_its_names() { + let mut s = session(); + let layer = pixel_layer(&mut s); + s.execute("layer.layerMask.revealAll", json!({"layer": layer})).unwrap(); + assert_eq!(step(&mut s, "select.loadSelection", json!({"channel": "transparency"})), "Load Transparency"); + assert_eq!(step(&mut s, "select.loadSelection", json!({"channel": "mask"})), "Load Layer Mask"); +} + +/// ⇧-click on a mask and the chain say which way they went; the Layer menu's plain toggles keep their names. +#[test] +fn mask_toggles_and_chains_name_their_direction() { + let mut s = session(); + let layer = pixel_layer(&mut s); + s.execute("layer.layerMask.revealAll", json!({"layer": layer})).unwrap(); + s.execute("layer.vectorMask.revealAll", json!({"layer": layer})).unwrap(); + let cases = [ + ("layer.layerMask.enabled", "enabled", ["Disable Layer Mask", "Enable Layer Mask"], "Enable/Disable Layer Mask"), + ("layer.layerMask.linked", "linked", ["Unlink Mask", "Link Mask"], "Link/Unlink Layer Mask"), + ("layer.vectorMask.enabled", "enabled", ["Disable Vector Mask", "Enable Vector Mask"], "Edit Vector Mask"), + ("layer.vectorMask.linked", "linked", ["Unlink Vector Mask", "Link Vector Mask"], "Edit Vector Mask"), + ]; + for (cmd, key, [off, on], toggle) in cases { + assert_eq!(step(&mut s, cmd, json!({"layer": layer, key: false})), off); + assert_eq!(step(&mut s, cmd, json!({"layer": layer, key: true})), on); + assert_eq!(step(&mut s, cmd, json!({})), toggle, "{cmd} from the menu"); + } +} + +/// Dragging a layer mask onto another layer, or ⌥-dragging a copy there, is one `Add Layer Mask` state, and one undo +/// puts both layers back. +#[test] +fn a_mask_drop_is_one_add_layer_mask_state() { + for copy in [false, true] { + let mut s = session(); + let from = pixel_layer(&mut s); + let to = pixel_layer(&mut s); + s.execute("layer.layerMask.revealAll", json!({"layer": from})).unwrap(); + let before = s.active().unwrap().doc.clone(); + assert_eq!(step(&mut s, "layer.layerMask.moveTo", json!({"layer": from, "to": to, "copy": copy})), "Add Layer Mask", "copy {copy}"); + s.execute("edit.undo", json!({})).unwrap(); + let doc = &s.active().unwrap().doc; + for id in [from, to] { + let has_mask = |d: &photocraft_doc::Document| d.layer(photocraft_doc::LayerId(id)).unwrap().mask.is_some(); + assert_eq!(has_mask(doc), has_mask(&before), "copy {copy}: one undo restores layer {id}"); + } + } +} diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index 69b4cb0840..eac618e76d 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -92,6 +92,7 @@ mod layer_delete_last; mod layer_mask_depth; mod layer_props_several; mod layer_range_panel_order; +mod layers_thumbnail_history_names; mod live_dab_matches_replay; mod live_line_transform; mod magnetic_lasso_composite; From 17252c46254519ac3181713678d668086b4c0357 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:28:57 +0100 Subject: [PATCH 3/3] Free Transform: refuse group Warp before a background prepare, grey it during a commit (#16731) A large group's box opens only when its preparing job lands, so Warp now checks for a group before Free Transform starts. The open-box rule that greys the Warp block for several layers or a group now runs before the pending-commit branch too. --- .../ui-egui/src/tools/transform_tool/begin.rs | 18 +++++++++++++ .../src/tools/transform_tool/commit.rs | 25 +++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/tools/transform_tool/begin.rs b/crates/ui-egui/src/tools/transform_tool/begin.rs index 0756c0cfff..53ad4b623d 100644 --- a/crates/ui-egui/src/tools/transform_tool/begin.rs +++ b/crates/ui-egui/src/tools/transform_tool/begin.rs @@ -392,6 +392,21 @@ fn warp_refusal(app: &PhotocraftApp) -> Option<&'static str> { if !t.layers.is_empty() { Some(WARP_ONE_LAYER) } else { moves_group(app, t).then_some(WARP_GROUP) } } +/// Would [`begin`] box the active group as one layer? Asked before it runs: a large layer's box +/// opens only when its preparing job lands, too late for [`warp_refusal`]. +fn opens_group_box(app: &PhotocraftApp) -> bool { + if crate::vector_ui::free_transform_path(app).is_some() { + return false; + } + let target = crate::canvas::paint_target(app); + let Some(st) = app.session.active() else { return false }; + let Some(id) = st.active_layer else { return false }; + let targets = photocraft_engine::transform_cmds::box_targets(&st.doc, &photocraft_engine::transform_cmds::selection_targets(st)); + targets == [id] + && photocraft_engine::transform_cmds::lone_target(&st.doc, Some(id), &json!({ "target": target })).is_ok_and(|t| t.is_none()) + && st.doc.layer(id).is_some_and(|l| matches!(l.content, LayerContent::Group(_))) +} + /// Free Transform on a copy (⌥⌘T, no menu item): duplicates the active layer (with a selection, /// its selected pixels, as Layer via Copy) and transforms the copy (#352). pub fn begin_copy(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> { @@ -708,6 +723,9 @@ pub fn begin_warp(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), St return Err(why.into()); } if app.ui.transform.is_none() { + if opens_group_box(app) { + return Err(WARP_GROUP.into()); + } begin(app, ctx)?; if let Some(why) = warp_refusal(app) { cancel(app); diff --git a/crates/ui-egui/src/tools/transform_tool/commit.rs b/crates/ui-egui/src/tools/transform_tool/commit.rs index 7829c4c3af..29276a3206 100644 --- a/crates/ui-egui/src/tools/transform_tool/commit.rs +++ b/crates/ui-egui/src/tools/transform_tool/commit.rs @@ -398,6 +398,20 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option { return Some(false); } let t = app.ui.transform.as_ref()?; + // One box over several layers doesn't warp (#6501), nor one over a group (#16731), and not + // while its commit runs either. + if matches!( + id, + "edit.transform.warp" + | "layer.smartObjects.warp" + | "edit.transform.splitWarpCrosswise" + | "edit.transform.splitWarpHorizontally" + | "edit.transform.splitWarpVertically" + | "edit.transform.removeWarpSplit" + ) && (!t.layers.is_empty() || moves_group(app, t)) + { + return Some(false); + } if committing(app).is_some() { return box_command(id).then_some(false); } @@ -414,17 +428,6 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option { SAVE_FOR_WEB | COPY_CSS => Some(false), // Rotate and Flip turn the box (not while warping, where the mesh is the box). _ if preset_for_command(id).is_some() => Some(t.session.warp().is_none()), - // One box over several layers doesn't warp (#6501), nor one over a group (#16731). - "edit.transform.warp" - | "layer.smartObjects.warp" - | "edit.transform.splitWarpCrosswise" - | "edit.transform.splitWarpHorizontally" - | "edit.transform.splitWarpVertically" - | "edit.transform.removeWarpSplit" - if !t.layers.is_empty() || moves_group(app, t) => - { - Some(false) - } // Editable type can't be distorted (#2630, as #2701 rules for the menus outside a box). "edit.transform.distort" | "edit.transform.perspective" if moves_type(app, t) => Some(false), _ => None,