From 1a835fe96d2c222db8bb00cd7d645d662868403f Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:04:25 +0100 Subject: [PATCH 1/2] Layers: a second click on the targeted vector mask un-targets it (#16783) A click on the active layer's targeted vector mask thumbnail now hands the target back to the layer's pixels and drops the mask's path from Paths. The layer mask keeps its target on a second click. A plain double click no longer re-targets the vector mask, so its first click decides, as in the reference; a double click with modifiers keeps today's behaviour. --- crates/ui-egui/src/panels/layers_events.rs | 18 +++- .../panels/layers_vector_mask_click_tests.rs | 87 +++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/panels/layers_vector_mask_click_tests.rs diff --git a/crates/ui-egui/src/panels/layers_events.rs b/crates/ui-egui/src/panels/layers_events.rs index 36344f5f94..21dbd68b49 100644 --- a/crates/ui-egui/src/panels/layers_events.rs +++ b/crates/ui-egui/src/panels/layers_events.rs @@ -324,6 +324,14 @@ fn target_on_click(app: &mut PhotocraftApp, l: &Layer, was_active: bool, part: O return; } match part { + // A second click on the targeted vector mask un-targets it: the pixels take the target and + // Paths drops the mask's path (#16783). The layer mask stays targeted instead. + Some(LayerPart::VectorMask) if was_active && app.ui.vector_mask_target => { + if app.ui.selected_path.as_deref() == Some("layer") { + app.ui.selected_path = None; + } + actions.push(("ui.vectorMaskTarget".into(), json!(false))); + } Some(LayerPart::VectorMask) => { app.ui.selected_path = Some("layer".into()); actions.push(("ui.vectorMaskTarget".into(), json!(true))); @@ -371,7 +379,11 @@ fn activate( let command = match on { ActivateOn::Thumbnail(LayerPart::LayerMask | LayerPart::VectorMask) => { let kind = if on == ActivateOn::Thumbnail(LayerPart::VectorMask) { MaskKind::Vector } else { MaskKind::Pixel }; - actions.push((if kind == MaskKind::Vector { "ui.vectorMaskTarget" } else { "ui.maskTarget" }.into(), json!(true))); + // A plain double click's first click has already targeted the vector mask, or un-targeted the + // targeted one, which this leaves as it is (#16783). + if kind == MaskKind::Pixel || !ctx.input(|i| i.modifiers.is_none()) { + actions.push((if kind == MaskKind::Vector { "ui.vectorMaskTarget" } else { "ui.maskTarget" }.into(), json!(true))); + } match crate::mask_thumbs_ui::double_click_command(app, kind) { Some((cmd, val)) => actions.push((cmd.into(), val)), None => actions.push(("ui.properties".into(), json!(true))), @@ -669,3 +681,7 @@ pub(crate) fn run_actions(app: &mut PhotocraftApp, ctx: &egui::Context, actions: let _ = app.run(&id, p); } } + +#[cfg(test)] +#[path = "layers_vector_mask_click_tests.rs"] +mod layers_vector_mask_click_tests; diff --git a/crates/ui-egui/src/panels/layers_vector_mask_click_tests.rs b/crates/ui-egui/src/panels/layers_vector_mask_click_tests.rs new file mode 100644 index 0000000000..2d09ac1c41 --- /dev/null +++ b/crates/ui-egui/src/panels/layers_vector_mask_click_tests.rs @@ -0,0 +1,87 @@ +//! #16783: a second click on the targeted vector mask thumbnail un-targets it, while the layer mask +//! stays targeted. Each click is a `LayersEvent::Select` sent through `apply_layers_events`, as the +//! panel reports it. + +use craft::behavior::SelectionChange; +use craft::layers::ui::panel::{ActivateOn, LayerSelect, LayersEvent}; +use craft::layers::ui::tree::{LayerPart, LayerRowKey}; +use photocraft_doc::LayerId; +use serde_json::json; + +use super::apply_layers_events; +use super::tests::session; +use crate::PhotocraftApp; + +fn app_of(s: photocraft_engine::Session) -> Box { + let mut app = PhotocraftApp::new(s, crate::Services::default()); + app.background_jobs = false; + app.sync_views(); + app +} + +fn click(app: &mut PhotocraftApp, layer: u64, part: LayerPart) { + let ctx = app.ctx().clone(); + let event = LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![LayerId(layer)]), Some(part))); + apply_layers_events(app, &ctx, vec![event]); +} + +/// A double click as the panel reports it: the first click selects, the second only activates. +fn double_click(app: &mut PhotocraftApp, layer: u64, part: LayerPart) { + click(app, layer, part); + let ctx = app.ctx().clone(); + apply_layers_events(app, &ctx, vec![LayersEvent::activate(LayerRowKey::Layer(LayerId(layer)), ActivateOn::Thumbnail(part))]); +} + +fn vector_mask_targeted(app: &PhotocraftApp) -> bool { + app.ui.vector_mask_target && !app.ui.mask_target && app.ui.selected_path.as_deref() == Some("layer") +} + +#[test] +fn a_second_click_on_the_targeted_vector_mask_untargets_it() { + let (s, masked, _) = session(); + let mut app = app_of(s); + click(&mut app, masked, LayerPart::VectorMask); + assert!(vector_mask_targeted(&app)); + click(&mut app, masked, LayerPart::VectorMask); + assert!(!app.ui.vector_mask_target && !app.ui.mask_target, "the layer's pixels are the target"); + assert_eq!(app.ui.selected_path, None, "Paths no longer selects the mask's path"); + assert_eq!(crate::canvas::paint_target(&app), json!("pixels")); + assert_eq!(app.session.active().unwrap().active_layer, Some(LayerId(masked)), "the layer stays active"); + click(&mut app, masked, LayerPart::VectorMask); + assert!(vector_mask_targeted(&app), "a third click targets it again"); +} + +#[test] +fn a_double_click_toggles_the_vector_mask_target_with_its_first_click() { + let (s, masked, _) = session(); + let mut app = app_of(s); + double_click(&mut app, masked, LayerPart::VectorMask); + assert!(vector_mask_targeted(&app), "on an untargeted vector mask, the double click targets it"); + double_click(&mut app, masked, LayerPart::VectorMask); + assert!(!app.ui.vector_mask_target && !app.ui.mask_target, "on the targeted one, its first click un-targets it"); + assert_eq!(app.ui.selected_path, None); +} + +#[test] +fn a_second_click_on_the_targeted_layer_mask_keeps_it_targeted() { + let (s, masked, _) = session(); + let mut app = app_of(s); + click(&mut app, masked, LayerPart::LayerMask); + click(&mut app, masked, LayerPart::LayerMask); + assert!(app.ui.mask_target && !app.ui.vector_mask_target); + assert_eq!(crate::canvas::paint_target(&app), json!("mask")); +} + +#[test] +fn the_vector_mask_of_another_layer_is_targeted_while_one_is_targeted() { + let (mut s, masked, _) = session(); + let other = s.execute("layer.new.layer", json!({"name": "Other"})).unwrap()["layer"].as_u64().unwrap(); + let path = json!({"subpaths": [{"knots": [[10, 10], [60, 10], [60, 60]]}]}); + s.execute("layer.vectorMask.add", json!({"layer": other, "path": path})).unwrap(); + s.execute("layer.select", json!({"layer": masked})).unwrap(); + let mut app = app_of(s); + click(&mut app, masked, LayerPart::VectorMask); + click(&mut app, other, LayerPart::VectorMask); + assert_eq!(app.session.active().unwrap().active_layer, Some(LayerId(other))); + assert!(vector_mask_targeted(&app), "the first click on another layer's vector mask targets it"); +} From b54d5f2fed4800be2cd9bd67b1552020e30d19ab Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:38:41 +0100 Subject: [PATCH 2/2] Re-run CI (unrelated Remove tool background-job timing failure)