PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Layers: ⌘-click on the Background thumbnail is a plain click, as in Photoshop (#7165)
Unemars5071472e4d94
diff --git a/crates/ui-egui/src/layer_shortcut_tests.rs b/crates/ui-egui/src/layer_shortcut_tests.rsindex a363c340b..96ab2520d 100644--- a/crates/ui-egui/src/layer_shortcut_tests.rs+++ b/crates/ui-egui/src/layer_shortcut_tests.rs@@ -122,3 +122,69 @@ fn alt_click_on_a_layer_thumbnail_fits_the_layer() {assert_eq!(v.center, [310.0, 205.0], "centred on the layer's content");assert!(v.zoom > before.zoom * 4.0, "zoomed in on 20 × 10 px: {} -> {}", before.zoom, v.zoom);}++/// ⌘-click a layer's thumbnail loads its transparency as a selection without changing the+/// selected layer; on the Background, which has no transparency, it is a plain click, and a hidden+/// layer still loads (measured on Photoshop 25.4, 2026-10-17).+#[test]+fn command_click_on_a_thumbnail_loads_transparency_except_on_the_background() {+ use egui::{Event, PointerButton, pos2, vec2};+ let mut s = photocraft_engine::Session::new();+ s.execute("file.new", json!({"width": 400, "height": 300})).unwrap();+ let background = s.active().unwrap().active_layer.unwrap().0;+ let shape = s.execute("layer.new.layer", json!({"name": "Shape"})).unwrap()["layer"].as_u64().unwrap();+ s.execute("select.rect", json!({"x": 100, "y": 50, "width": 120, "height": 100})).unwrap();+ s.execute("edit.fill", json!({"contents": "black"})).unwrap();+ s.execute("select.deselect", json!({})).unwrap();+ s.execute("layer.new.layer", json!({"name": "Top"})).unwrap();+ let mut h = egui_kittest::Harness::builder().with_size(vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());+ PhotocraftApp::new(s, crate::Services::default())+ });+ let ctx = h.ctx.clone();+ let (r, _) = crate::control::ControlRequest::new("ui.set", json!({"dock": {"collapsed": ["color", "properties", "history", "navigator"]}}));+ crate::control::handle(h.state_mut(), &ctx, &r);+ h.run_steps(8);+ let click = |h: &mut egui_kittest::Harness<'_, PhotocraftApp>, layer: u64, modifiers: Modifiers| {+ let row = crate::layer_row_ui::recorded(&h.ctx).into_iter().find(|r| r.layer == layer).unwrap().row;+ let at = pos2(row.left() + 46.0, row.center().y);+ h.hover_at(at);+ h.event(Event::ModifiersChanged(modifiers));+ h.run_steps(1);+ h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers });+ h.run_steps(1);+ h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers });+ h.run_steps(1);+ h.event(Event::ModifiersChanged(Modifiers::NONE));+ h.run_steps(3);+ };+ let bounds = |h: &egui_kittest::Harness<'_, PhotocraftApp>| {+ let st = h.state().session.active().unwrap();+ st.doc.selection.as_ref().map(|s| s.content_bounds())+ };+ let top = h.state().session.active().unwrap().active_layer.unwrap();+ let selected = |h: &egui_kittest::Harness<'_, PhotocraftApp>| h.state().session.active().unwrap().selected_layers();+ click(&mut h, shape, Modifiers::COMMAND);+ assert_eq!(bounds(&h), Some(photocraft_geom::Rect::new(100, 50, 220, 150)), "the layer's pixels are selected");+ assert_eq!(h.state().session.active().unwrap().active_layer, Some(top), "the selected layer stays");+ assert_eq!(selected(&h), vec![top]);+ click(&mut h, background, Modifiers::COMMAND);+ assert_eq!(+ bounds(&h),+ Some(photocraft_geom::Rect::new(100, 50, 220, 150)),+ "the Background has no transparency to load: a plain click, which leaves the selection and selects the row"+ );+ assert_eq!(h.state().session.active().unwrap().active_layer, Some(photocraft_doc::LayerId(background)));+ assert_eq!(selected(&h), vec![photocraft_doc::LayerId(background)], "the Background alone, not toggled into the set");+ // Already in a multi-selection: the ⌘-click still leaves it the only selected layer.+ h.state_mut().run("layer.select", json!({"layer": top.0})).unwrap();+ h.state_mut().run("layer.select", json!({"layer": background, "mode": "add"})).unwrap();+ h.run_steps(2);+ assert_eq!(selected(&h).len(), 2);+ click(&mut h, background, Modifiers::COMMAND);+ assert_eq!(selected(&h), vec![photocraft_doc::LayerId(background)], "replaced, not removed from the set");+ assert_eq!(h.state().session.active().unwrap().active_layer, Some(photocraft_doc::LayerId(background)));+ h.state_mut().run("layer.setProps", json!({"layer": shape, "visible": false})).unwrap();+ click(&mut h, shape, Modifiers::COMMAND);+ assert_eq!(bounds(&h), Some(photocraft_geom::Rect::new(100, 50, 220, 150)), "a hidden layer's transparency loads too");+}diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 609007a5e..75ade83b8 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -3144,7 +3144,9 @@ fn layer_row(if let Some(kind) = masks.hit(p) {return Some(crate::mask_thumbs_ui::load_params(l, kind, m));}- thumb.expand(2.0).contains(p).then(|| json!({"channel": "transparency", "layer": l.id.0, "operation": crate::channels_panel::load_operation(m)}))+ // The Background has no transparency to load: Photoshop treats the click as a plain one.+ (!doc.is_background(l.id) && thumb.expand(2.0).contains(p))+ .then(|| json!({"channel": "transparency", "layer": l.id.0, "operation": crate::channels_panel::load_operation(m)}))});// ⇧-click a mask thumbnail: disable / enable that mask; ⌥-click a layer mask: view it.let mask_toggle = resp.clicked().then(|| (ui.input(|i| i.modifiers), resp.interact_pointer_pos())).and_then(|(m, pos)| {@@ -3156,14 +3158,17 @@ fn layer_row(} else if let Some(cmd) = mask_toggle {actions.push(cmd);} else if resp.clicked() && !eye_resp.clicked() && !toggled && !fx_toggled && !masks.clicked {- let mode = select_mode(ui.input(|i| i.modifiers));+ let m = ui.input(|i| i.modifiers);+ let pos = resp.interact_pointer_pos();+ let on_thumb = pos.is_some_and(|p| thumb.expand(2.0).contains(p));+ // ⌘-click on the Background thumbnail stands in for the plain click (there is no+ // transparency to load): it selects the Background alone, not toggled into the set.+ let mode = if m.command && on_thumb && doc.is_background(l.id) { "replace" } else { select_mode(m) };actions.push(("layer.select".into(), json!({"layer": l.id.0, "mode": mode})));crate::smart_ui::deselect(ctx, doc.id);// A thumbnail explicitly selects content or a mask. Selecting an adjustment/fill row// defaults to its mask, but clicking its content thumbnail must leave the mask target.- let pos = resp.interact_pointer_pos();let on_mask = mask_rect.zip(pos).is_some_and(|(r, p)| r.expand(2.0).contains(p));- let on_thumb = pos.is_some_and(|p| thumb.expand(2.0).contains(p));let on_vector = pos.and_then(|p| masks.hit(p)) == Some(crate::mask_thumbs_ui::MaskKind::Vector);// Clicking the layer thumbnail leaves mask view (#196).let viewing = app.session.active().and_then(photocraft_engine::mask_view_cmds::current).is_some_and(|v| v.layer == l.id);@@ -3186,7 +3191,6 @@ fn layer_row(actions.push(("ui.maskTarget".into(), json!(false)));}// ⌥-click the layer thumbnail: fit the layer on screen, as Photoshop does.- let m = ui.input(|i| i.modifiers);if on_thumb && m.alt && !m.shift && !m.command {actions.push(("view.fitLayersOnScreen".into(), Value::Null));}