PhotoCraft: An open-source, photo editor written by scratch in pure Rust
feat: Photoshop's layer and selection keys (Ctrl+, toggle, Ctrl+\, /, Ctrl+Alt+2, Ctrl+Alt+Backspace, Tab rename, Alt-click thumbnail) (#3710)
FinnNk53d814f6437d
diff --git a/crates/engine/src/channel_cmds.rs b/crates/engine/src/channel_cmds.rsindex a85ff75b7..39ce9c825 100644--- a/crates/engine/src/channel_cmds.rs+++ b/crates/engine/src/channel_cmds.rs@@ -1804,6 +1804,16 @@ pub fn specs() -> Vec<CommandSpec> {journal: false,},spec!("channel.target.composite", "Target Composite Channel", [], Some("Cmd+2"), "{}", has_doc, |s, _| target_slot(s, 2)),+ // ⌘\ targets the active layer's mask, as clicking its thumbnail does.+ spec!("channel.target.layerMask", "Target Layer Mask", [], Some("Cmd+\\"), "{}", has_layer_mask, |s, _| target_cmd(+ s,+ &serde_json::json!({"channel": "mask"})+ )),+ // ⌘⌥2 loads the image's luminosity as a selection (⌘-click on the composite channel).+ spec!("select.loadLuminosity", "Load Luminosity", [], Some("Cmd+Alt+2"), "{}", has_doc, |s, _| load_selection(+ s,+ &serde_json::json!({"channel": "composite"})+ )),spec!("channel.target.slot3", "Target Channel 3", [], Some("Cmd+3"), "{}", slot_ok::<3>, |s, _| target_slot(s, 3)),spec!("channel.target.slot4", "Target Channel 4", [], Some("Cmd+4"), "{}", slot_ok::<4>, |s, _| target_slot(s, 4)),spec!("channel.target.slot5", "Target Channel 5", [], Some("Cmd+5"), "{}", slot_ok::<5>, |s, _| target_slot(s, 5)),@@ -1814,6 +1824,13 @@ pub fn specs() -> Vec<CommandSpec> {]}+/// Target Layer Mask: the active layer has a mask.+fn has_layer_mask(s: &Session) -> std::result::Result<(), String> {+ let st = s.active().ok_or("no document open")?;+ let layer = st.active_layer.and_then(|id| st.doc.layer(id)).ok_or("no active layer")?;+ layer.mask.as_ref().map(|_| ()).ok_or_else(|| "the active layer has no layer mask".to_string())+}+fn slot_ok<const N: usize>(s: &Session) -> std::result::Result<(), String> {let d = s.active().ok_or("no document open")?;let colors = color_count(&d.doc);diff --git a/crates/engine/src/channel_cmds/tests.rs b/crates/engine/src/channel_cmds/tests.rsindex 1223c0589..17727dc8a 100644--- a/crates/engine/src/channel_cmds/tests.rs+++ b/crates/engine/src/channel_cmds/tests.rs@@ -741,6 +741,33 @@ fn clear_with_an_alpha_channel_or_quick_mask_targeted_fills_it_not_the_layer() {assert_eq!(px(&s, 5, 5), layer, "the layer is untouched in Quick Mask mode");}+#[test]+fn command_backslash_targets_the_layer_mask_and_command_2_the_composite() {+ let mut s = session();+ s.execute("layer.new.layer", json!({})).unwrap();+ assert!(!s.is_enabled("channel.target.layerMask"), "no mask yet");+ assert!(s.execute("channel.target.layerMask", json!({})).is_err());+ s.execute("layer.layerMask.revealAll", json!({})).unwrap();+ s.execute("channel.target.composite", json!({})).unwrap();+ assert_eq!(crate::commands::find("channel.target.layerMask").and_then(|c| c.shortcut), Some("Cmd+\\"));+ s.execute("channel.target.layerMask", json!({})).unwrap();+ assert_eq!(s.active().unwrap().channel_view.target, ChannelTarget::LayerMask);+ s.execute("channel.target.composite", json!({})).unwrap();+ assert_eq!(s.active().unwrap().channel_view.target, ChannelTarget::Composite);+}++#[test]+fn command_alt_2_loads_the_images_luminosity() {+ let mut s = session();+ rect(&mut s, 0, 0, 20, 20, "replace");+ s.execute("edit.fill", json!({"contents": "black"})).unwrap();+ s.execute("select.deselect", json!({})).unwrap();+ assert_eq!(crate::commands::find("select.loadLuminosity").and_then(|c| c.shortcut), Some("Cmd+Alt+2"));+ s.execute("select.loadLuminosity", json!({})).unwrap();+ assert!(sel_at(&s, 5, 5) < 0.01, "black: unselected");+ assert!(sel_at(&s, 30, 5) > 0.99, "white: selected");+}+#[test]fn thumbnail_selection_shape_without_pixel_cache_uses_its_transparency() {for depth in [8, 16, 32] {diff --git a/crates/engine/src/extra_cmds.rs b/crates/engine/src/extra_cmds.rsindex cebb9ec89..251acfb3f 100644--- a/crates/engine/src/extra_cmds.rs+++ b/crates/engine/src/extra_cmds.rs@@ -566,6 +566,35 @@ fn set_visible(s: &mut Session, p: &Value, visible: bool) -> Result<Value> {Ok(Value::Null)}+/// Layer › Hide Layers (⌘,): hide the targeted layers, or show them when every one is already+/// hidden, as Photoshop's item does (it reads Show Layers then), so ⌘, toggles.+fn hide_or_show(s: &mut Session, p: &Value) -> Result<Value> {+ let st = s.active().ok_or(EngineError::NoDocument)?;+ let targets = if crate::layer_multi_cmds::multi(s, p) { crate::layer_multi_cmds::selected(s) } else { vec![layer_param(s, p)?] };+ let all_hidden = targets.iter().all(|id| st.doc.layer(*id).is_some_and(|l| !l.visible));+ set_visible(s, p, all_hidden)+}++/// `/`: Lock Transparent Pixels on or off for the targeted layers, as the Layers panel's first lock+/// button does. With several layers targeted, any unlocked one means lock them all. The+/// Background, which can't take this lock, is left out.+fn toggle_lock_transparency(s: &mut Session, p: &Value) -> Result<Value> {+ let st = s.active().ok_or(EngineError::NoDocument)?;+ let targets: Vec<LayerId> = if crate::layer_multi_cmds::multi(s, p) { crate::layer_multi_cmds::selected(s) } else { vec![layer_param(s, p)?] };+ let targets: Vec<LayerId> = targets.into_iter().filter(|id| st.doc.layer(*id).is_some_and(|l| !st.doc.is_background(l.id))).collect();+ if targets.is_empty() {+ return Err(EngineError::Other("the Background layer can't lock transparent pixels".into()));+ }+ let lock = !targets.iter().all(|id| st.doc.layer(*id).is_some_and(|l| l.locks.transparency));+ s.edit(if lock { "Lock Transparent Pixels" } else { "Unlock Transparent Pixels" }, |doc, _| {+ for id in &targets {+ doc.layer_mut(*id).ok_or(EngineError::NoLayer(*id))?.locks.transparency = lock;+ }+ Ok(())+ })?;+ Ok(json!({"locked": lock}))+}+/// Is the layer at `path` shown alone: it and its enclosing groups visible, every layer outside/// it hidden (the layers inside a group keep their own visibility)?fn shown_alone(doc: &Document, path: &[usize]) -> bool {@@ -916,8 +945,25 @@ pub fn specs() -> Vec<CommandSpec> {},ungroup),- spec!("layer.hideLayers", "Hide Layers", &["Layer"], Some("Cmd+,"), r##"{"layer":id?}"##, has_layer, |s, p| set_visible(s, p, false)),+ spec!(+ "layer.hideLayers",+ "Hide Layers",+ &["Layer"],+ Some("Cmd+,"),+ r##"{"layer":id?} (shows them instead when every targeted layer is already hidden, so ⌘, toggles)"##,+ has_layer,+ hide_or_show+ ),spec!("layer.showLayers", "Show Layers", &[], None, r##"{"layer":id?}"##, has_layer, |s, p| set_visible(s, p, true)),+ spec!(+ "layer.toggleLockTransparency",+ "Lock Transparent Pixels",+ &[],+ Some("/"),+ r##"{"layer":id?} (toggles; several layers selected: locks them all unless every one is locked)"##,+ has_layer,+ toggle_lock_transparency+ ),spec!("layer.showOnly","Show Only This Layer",@@ -1496,6 +1542,48 @@ mod tests {assert_eq!(doc(&s).layers[0].name, "Background");}+ #[test]+ fn hide_layers_toggles_once_every_target_is_hidden() {+ let mut s = session(8);+ s.execute("layer.new.layer", json!({})).unwrap();+ let b = active(&s).id;+ let visible = |s: &Session| doc(s).layer(b).unwrap().visible;+ // Select › All Layers leaves out the Background, as in Photoshop.+ let all = |s: &Session| crate::layer_multi_cmds::selected(s).iter().map(|id| doc(s).layer(*id).unwrap().visible).collect::<Vec<_>>();+ s.execute("layer.hideLayers", json!({})).unwrap();+ assert!(!visible(&s));+ s.execute("layer.hideLayers", json!({})).unwrap();+ assert!(visible(&s), "⌘, again shows it");+ // Several selected: any one still shown means hide them all; then they all come back.+ s.execute("layer.hideLayers", json!({"layer": b.0})).unwrap();+ s.execute("select.allLayers", json!({})).unwrap();+ assert!(all(&s).len() > 1);+ s.execute("layer.hideLayers", json!({})).unwrap();+ assert!(all(&s).iter().all(|v| !v));+ s.execute("layer.hideLayers", json!({})).unwrap();+ assert!(all(&s).iter().all(|v| *v));+ }++ #[test]+ fn slash_toggles_lock_transparent_pixels_but_not_on_the_background() {+ let mut s = session(8);+ let bg = doc(&s).layers[0].id;+ assert!(doc(&s).is_background(bg));+ s.execute("layer.new.layer", json!({})).unwrap();+ let top = active(&s).id;+ let locked = |s: &Session, id: LayerId| doc(s).layer(id).unwrap().locks.transparency;+ assert_eq!(s.execute("layer.toggleLockTransparency", json!({})).unwrap()["locked"], true);+ assert!(locked(&s, top));+ s.execute("layer.toggleLockTransparency", json!({})).unwrap();+ assert!(!locked(&s, top));+ s.undo();+ assert!(locked(&s, top), "one undoable step each");+ let bg_locks = doc(&s).layer(bg).unwrap().locks;+ assert!(s.execute("layer.toggleLockTransparency", json!({"layer": bg.0})).is_err());+ assert_eq!(doc(&s).layer(bg).unwrap().locks, bg_locks, "the Background is left alone");+ assert!(s.execute("layer.toggleLockTransparency", json!({"layer": 999_999})).is_err());+ }+#[test]fn layer_utilities() {let mut s = session(8);diff --git a/crates/engine/src/fill_key_cmds.rs b/crates/engine/src/fill_key_cmds.rsindex 6235b629b..2ae2fe4df 100644--- a/crates/engine/src/fill_key_cmds.rs+++ b/crates/engine/src/fill_key_cmds.rs@@ -1,5 +1,6 @@//! Photoshop's fill keys (#249): ⌥⌫ fills the selection (or the whole layer) with the foreground-//! colour, ⌘⌫ with the background colour, and with ⇧ added they preserve transparency. Photoshop+//! colour, ⌘⌫ with the background colour, and with ⇧ added they preserve transparency. ⌘⌥⌫ fills+//! from history: the History Brush's source state (the oldest state still held). Photoshop//! has no menu item for them; here they are ordinary commands with default shortcuts, so they//! appear in Edit › Keyboard Shortcuts (Tools) and can be rebound, recorded and driven by agents.//!@@ -12,7 +13,7 @@ use crate::commands::CommandSpec;use crate::{EngineError, Result, Session};/// The fill-key command ids (routed to the Channels panel target like `edit.fill`).-pub const IDS: [&str; 4] = ["edit.fillForeground", "edit.fillBackground", "edit.fillForegroundPreserve", "edit.fillBackgroundPreserve"];+pub const IDS: [&str; 5] = ["edit.fillForeground", "edit.fillBackground", "edit.fillForegroundPreserve", "edit.fillBackgroundPreserve", "edit.fillHistory"];const PARAMS: &str = r##"{"layer":id?,"target":"pixels"|"mask"|"quickMask"|{"channel":i}?}"##;@@ -39,6 +40,22 @@ fn fill(s: &mut Session, p: &Value, cmd: &str, background: bool, preserve: bool)(edit_fill.run)(s, &Value::Object(q))}+/// ⌘⌥⌫: `edit.fill` from history, the History Brush's source unless `state` names another.+fn fill_history(s: &mut Session, p: &Value) -> Result<Value> {+ const CMD: &str = "edit.fillHistory";+ let mut q: Map<String, Value> = match p {+ Value::Object(m) => m.clone(),+ Value::Null => Map::new(),+ _ => return Err(EngineError::BadParams { cmd: CMD.into(), msg: "expected an object".into() }),+ };+ for k in ["color", "contents", "pattern"] {+ q.remove(k);+ }+ q.insert("contents".into(), json!("history"));+ let edit_fill = crate::commands::find("edit.fill").ok_or_else(|| EngineError::Other("Fill is unavailable".into()))?;+ (edit_fill.run)(s, &Value::Object(q))+}+pub fn specs() -> Vec<CommandSpec> {vec![CommandSpec {@@ -81,6 +98,16 @@ pub fn specs() -> Vec<CommandSpec> {run: |s, p| fill(s, p, "edit.fillBackgroundPreserve", true, true),journal: true,},+ CommandSpec {+ id: "edit.fillHistory",+ label: "Fill from History",+ menu: &[],+ shortcut: Some("Cmd+Alt+Backspace"),+ params: r##"{"state":n? (default: the History Brush's source, the oldest state still held),"layer":id?,"target":"pixels"|"mask"|"quickMask"|{"channel":i}?,"preserveTransparency":bool?}"##,+ enabled,+ run: fill_history,+ journal: true,+ },]}@@ -133,6 +160,27 @@ mod tests {}}+ #[test]+ fn fill_from_history_restores_the_history_brush_source_in_the_selection() {+ let mut s = session();+ assert_eq!(crate::commands::find("edit.fillHistory").and_then(|c| c.shortcut), Some("Cmd+Alt+Backspace"));+ s.execute("edit.fillForeground", json!({})).unwrap();+ s.execute("select.rect", json!({"x": 0, "y": 0, "width": 4, "height": 6})).unwrap();+ s.execute("edit.fillHistory", json!({})).unwrap();+ // The oldest state (the new, transparent layer) comes back inside the selection only.+ assert_eq!(px(&s, 1, 1)[3], 0.0);+ assert_eq!(px(&s, 6, 1), [1.0, 0.0, 0.0, 1.0]);+ // A named state, and refused ones change nothing.+ s.execute("select.deselect", json!({})).unwrap();+ let steps = s.active().unwrap().history.past_len();+ for bad in [json!({"state": 99}), json!({"state": "x"}), json!(7)] {+ assert!(s.execute("edit.fillHistory", bad.clone()).is_err(), "{bad}");+ }+ assert_eq!(s.active().unwrap().history.past_len(), steps);+ s.execute("edit.fillHistory", json!({"state": 1})).unwrap();+ assert_eq!(px(&s, 1, 1), [1.0, 0.0, 0.0, 1.0], "state 1 is after the foreground fill");+ }+#[test]fn background_fills_only_the_selection() {let mut s = session();diff --git a/crates/ui-egui/src/layer_row_ui.rs b/crates/ui-egui/src/layer_row_ui.rsindex d26569059..fb229fcbc 100644--- a/crates/ui-egui/src/layer_row_ui.rs+++ b/crates/ui-egui/src/layer_row_ui.rs@@ -295,8 +295,20 @@ pub fn end_rename(ctx: &egui::Context, commit: bool) -> Option<(String, Value)>if commit { r.commit_action() } else { None }}+/// Where Tab or ⇧Tab sends a rename: the layer it left and whether the next one is above.+fn next_rename_id() -> egui::Id {+ egui::Id::new("layer-rename-next")+}++/// The rename that Tab (`up` false) or ⇧Tab (`up` true) just left on `layer`, for the Layers panel+/// to continue on the layer below or above, as Photoshop does. Taken once.+pub fn take_next_rename(ctx: &egui::Context) -> Option<(u64, bool)> {+ ctx.data_mut(|d| d.remove_temp::<(u64, bool)>(next_rename_id()))+}+/// Draw the rename field of `layer` in `rect` when it is the one being renamed, and handle its-/// keys and focus. Returns the rename command when it was committed this frame.+/// keys and focus. Returns the rename command when it was committed this frame. Tab and ⇧Tab+/// commit too and ask for the next rename ([`take_next_rename`]).pub fn rename_field(ui: &mut egui::Ui, layer: u64, rect: Rect) -> Option<(String, Value)> {let ctx = ui.ctx().clone();let mut r = rename(&ctx).filter(|r| r.layer == layer)?;@@ -316,6 +328,10 @@ pub fn rename_field(ui: &mut egui::Ui, layer: u64, rect: Rect) -> Option<(Stringreturn None;}let (enter, tab, esc) = ctx.input(|i| (i.key_pressed(egui::Key::Enter), i.key_pressed(egui::Key::Tab), i.key_pressed(egui::Key::Escape)));+ if tab {+ let up = ctx.input(|i| i.modifiers.shift);+ ctx.data_mut(|d| d.insert_temp(next_rename_id(), (layer, up)));+ }if esc {store(&ctx, None);Nonediff --git a/crates/ui-egui/src/layer_row_ui/rename_tests.rs b/crates/ui-egui/src/layer_row_ui/rename_tests.rsindex a4e985a29..4a7ea135f 100644--- a/crates/ui-egui/src/layer_row_ui/rename_tests.rs+++ b/crates/ui-egui/src/layer_row_ui/rename_tests.rs@@ -1,6 +1,7 @@//! #314: renaming a layer in place works like Photoshop. A click anywhere else, Enter or Tab//! commits; Esc cancels; only one rename is open at a time, and starting another (double-click,-//! the context menu or Layer › Rename Layer) commits the first.+//! the context menu or Layer › Rename Layer) commits the first. Tab then renames the layer below,+//! ⇧Tab the layer above.use egui::{Event, Key, Modifiers, PointerButton, Pos2, pos2, vec2};use egui_kittest::Harness;@@ -127,7 +128,8 @@ fn enter_and_tab_commit_and_escape_cancels() {start(&mut h, b);type_text(&mut h, "By Tab");key(&mut h, Key::Tab);- assert_eq!((name(&h, b), renaming(&h.ctx)), ("By Tab".into(), None));+ assert_eq!((name(&h, b), renaming(&h.ctx)), ("By Tab".into(), Some(a)), "Tab commits and renames the layer below");+ key(&mut h, Key::Escape);start(&mut h, c);type_text(&mut h, "Never");@@ -143,6 +145,28 @@ fn enter_and_tab_commit_and_escape_cancels() {assert_eq!(name(&h, c), "Gamma");}+#[test]+fn shift_tab_renames_the_layer_above_and_tab_at_the_bottom_ends() {+ let (mut h, [a, b, c]) = harness(1.0);+ start(&mut h, b);+ type_text(&mut h, "Middle");+ h.event(Event::ModifiersChanged(Modifiers::SHIFT));+ h.event(Event::Key { key: Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::SHIFT });+ h.event(Event::Key { key: Key::Tab, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::SHIFT });+ h.run_steps(1);+ h.event(Event::ModifiersChanged(Modifiers::NONE));+ h.run_steps(2);+ assert_eq!((name(&h, b), renaming(&h.ctx)), ("Middle".into(), Some(c)), "⇧Tab renames the layer above");+ // Typing replaces the next layer's name too, as the whole name starts selected.+ type_text(&mut h, "Top");+ key(&mut h, Key::Enter);+ assert_eq!((name(&h, c), renaming(&h.ctx)), ("Top".into(), None));+ // Tab from the lowest layer ends the rename: the Background below isn't renamed in place.+ start(&mut h, a);+ key(&mut h, Key::Tab);+ assert_eq!(renaming(&h.ctx), None);+}+#[test]fn starting_another_rename_commits_the_first_and_only_one_is_open() {for ppp in [1.0, 2.0] {diff --git a/crates/ui-egui/src/layer_shortcut_tests.rs b/crates/ui-egui/src/layer_shortcut_tests.rsnew file mode 100644index 000000000..a363c340b--- /dev/null+++ b/crates/ui-egui/src/layer_shortcut_tests.rs@@ -0,0 +1,124 @@+//! Photoshop's layer and selection keys reach their commands: ⌘, toggles visibility, ⌘\ targets+//! the mask, / toggles Lock Transparent Pixels, ⌘⌥2 loads luminosity, ⌘⌥⌫ fills from history.++use egui::{Key, Modifiers};+use serde_json::json;++use crate::PhotocraftApp;++fn app() -> PhotocraftApp {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 20, "height": 10})).unwrap();+ app.run("layer.new.layer", json!({})).unwrap();+ app+}++fn press(app: &mut PhotocraftApp, key: Key, modifiers: Modifiers) {+ let ctx = egui::Context::default();+ let raw = egui::RawInput {+ events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }],+ ..Default::default()+ };+ ctx.begin_pass(raw);+ crate::shortcuts::handle(app, &ctx);+ ctx.end_pass().textures_delta.clear();+}++fn active(app: &PhotocraftApp) -> &photocraft_doc::Layer {+ let st = app.session.active().unwrap();+ st.doc.layer(st.active_layer.unwrap()).unwrap()+}++#[test]+fn command_comma_toggles_the_layers_visibility() {+ let mut app = app();+ press(&mut app, Key::Comma, Modifiers::COMMAND);+ assert!(!active(&app).visible);+ press(&mut app, Key::Comma, Modifiers::COMMAND);+ assert!(active(&app).visible);+}++#[test]+fn slash_toggles_lock_transparent_pixels() {+ let mut app = app();+ press(&mut app, Key::Slash, Modifiers::NONE);+ assert!(active(&app).locks.transparency);+ press(&mut app, Key::Slash, Modifiers::NONE);+ assert!(!active(&app).locks.transparency);+}++#[test]+fn command_backslash_targets_the_layer_mask() {+ let mut app = app();+ app.run("layer.layerMask.revealAll", json!({})).unwrap();+ app.run("channel.target.composite", json!({})).unwrap();+ press(&mut app, Key::Backslash, Modifiers::COMMAND);+ assert_eq!(app.session.active().unwrap().channel_view.target, photocraft_engine::channel_cmds::ChannelTarget::LayerMask);+ assert!(app.ui.mask_target && app.layer_mask_targeted(), "the Layers panel targets the mask too");+ // Ctrl+2 goes back to the layer's pixels, in the Layers panel and for the tools.+ press(&mut app, Key::Num2, Modifiers::COMMAND);+ assert_eq!(app.session.active().unwrap().channel_view.target, photocraft_engine::channel_cmds::ChannelTarget::Composite);+ assert!(!app.ui.mask_target && !app.layer_mask_targeted());+ // The same after targeting the mask by its thumbnail (the panel's own flag).+ app.ui.mask_target = true;+ app.sync_mask_targets();+ press(&mut app, Key::Num2, Modifiers::COMMAND);+ assert!(!app.ui.mask_target && !app.layer_mask_targeted());+}++#[test]+fn command_alt_2_loads_luminosity() {+ let mut app = app();+ press(&mut app, Key::Num2, Modifiers::COMMAND | Modifiers::ALT);+ assert!(app.session.active().unwrap().doc.selection.is_some(), "the white image's luminosity selects it all");+}++#[test]+fn command_alt_backspace_fills_from_history() {+ // The Background exists in the oldest state, so its pixels come back from there.+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 20, "height": 10})).unwrap();+ app.run("tools.setColors", json!({"foreground": "#ff0000"})).unwrap();+ app.run("edit.fillForeground", json!({})).unwrap();+ assert_eq!(active(&app).surface().unwrap().pixel(3, 3)[1], 0.0, "red");+ press(&mut app, Key::Backspace, Modifiers::COMMAND | Modifiers::ALT);+ assert_eq!(active(&app).surface().unwrap().pixel(3, 3)[1], 1.0, "white again");+}++/// ⌥-click a layer's thumbnail: select it and fit its content on screen.+#[test]+fn alt_click_on_a_layer_thumbnail_fits_the_layer() {+ use egui::{Event, PointerButton, pos2, vec2};+ let mut s = photocraft_engine::Session::new();+ s.execute("file.new", json!({"width": 400, "height": 300})).unwrap();+ let small = s.execute("layer.new.layer", json!({"name": "Small"})).unwrap()["layer"].as_u64().unwrap();+ s.execute("select.rect", json!({"x": 300, "y": 200, "width": 20, "height": 10})).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 before = h.state().ui.views[0].clone();+ let row = crate::layer_row_ui::recorded(&h.ctx).into_iter().find(|r| r.layer == small).unwrap().row;+ let at = pos2(row.left() + 46.0, row.center().y);+ h.hover_at(at);+ h.event(Event::ModifiersChanged(Modifiers::ALT));+ h.run_steps(1);+ h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::ALT });+ h.run_steps(1);+ h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::ALT });+ h.run_steps(1);+ h.event(Event::ModifiersChanged(Modifiers::NONE));+ h.run_steps(3);+ let app = h.state();+ assert_eq!(app.session.active().unwrap().active_layer, Some(photocraft_doc::LayerId(small)));+ let v = &app.ui.views[0];+ 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);+}diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 1115b9496..7705e3564 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -890,6 +890,16 @@ impl PhotocraftApp {if gate.is_some() {self.session.authorize = None;}+ // An explicit channel target (⌘2, ⌘\, ⌘3…) decides what the Layers panel targets too:+ // ⌘2 after the mask was targeted goes back to the layer's pixels.+ if result.is_ok() && id.starts_with("channel.target") {+ if let Some(t) = self.session.active().map(|st| st.channel_view.target) {+ use photocraft_engine::channel_cmds::ChannelTarget;+ self.ui.mask_target = t == ChannelTarget::LayerMask;+ self.ui.vector_mask_target = t == ChannelTarget::VectorMask;+ }+ self.sync_mask_targets();+ }result}@@ -2266,6 +2276,8 @@ mod pen_variants_tests;#[cfg(test)]mod color_replacement_tests;#[cfg(test)]+mod layer_shortcut_tests;+#[cfg(test)]mod pencil_tests;#[cfg(test)]diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 086d1c060..d908af7af 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -2254,6 +2254,16 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {let below = Rect::from_min_max(pos2(last_rect.left(), last_rect.bottom()), pos2(last_rect.right(), ui.clip_rect().bottom()));layer_drop_zone(app, &ctx, ui, below, (last, last_rect), "below", &mut actions);}+ // Tab / ⇧Tab in a rename: rename the layer below / above next, as in Photoshop. The+ // Background isn't renamed in place (double-clicking it converts it), so it ends there.+ if let Some((from, up)) = crate::layer_row_ui::take_next_rename(ui.ctx())+ && let Some(at) = drawn.iter().position(|(id, _)| id.0 == from)+ && let Some(&(next, _)) = if up { at.checked_sub(1).and_then(|i| drawn.get(i)) } else { drawn.get(at + 1) }+ && let Some(l) = doc.layer(next).filter(|l| !crate::doc_props_ui::is_background(&doc, l))+ && let Some(done) = crate::layer_row_ui::start_rename(ui.ctx(), next.0, &l.name)+ {+ actions.push(done);+ }// ⌥-click the line between two layers: clip / release the upper one (#967).crate::clip_line_ui::show(ui, &doc, &mut actions);// A rename whose row is gone (deleted, filtered out, inside a closed group) ends,@@ -2754,6 +2764,11 @@ fn layer_row(} else if on_thumb || !row.primary {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));+ }}// Double-click: the name renames in place (over the row's full height, not just the glyphs:// #651); the Background, which can't be renamed while it's locked, becomes a normal layer; andiff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex d168db4df..3daee822c 100644--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@ -1,6 +1,6 @@# UI parity: tools, handles, modifiers and feel-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-11 · **Change:** minor (⇧-dragged guides land on ruler ticks) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-11 · **Change:** minor (⇧-dragged guides land on ruler ticks; layer and selection keys) · **Target:** Adobe Photoshop 2026How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, thehandles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,@@ -183,6 +183,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme| `.kys` import | done (`engine/src/kys.rs`) | || Shortcut glyphs per platform | done (UI-217-19) | || Brush size/hardness keys on non-US layouts | done (#3109): `[` `]` need AltGr on many layouts, so Photoshop uses other keys there (German: Ö / #, ⇧ for hardness). `layout_keys.rs` has a data table of such layouts (`LAYOUTS`, add rows to support one more) and a fallback for all others: the keys at the US `[` / `]` positions act as `[` / `]` when they don't type brackets. Off once a real bracket is typed; Edit › Keyboard Shortcuts overrides still apply | |+| Layer and selection keys: ⌘, toggles visibility, ⌘\ targets the mask, / locks transparency, ⌘⌥2 loads luminosity, ⌘⌥⌫ fills from history, Tab / ⇧Tab rename the next layer, ⌥-click a thumbnail fits the layer | done (2026-10-11) | |## Panels and workspace@@ -215,3 +216,4 @@ Paragraph; the rest open as in-app floating windows.| 2026-10-11 | minor | Flick panning done: releasing a moving Hand drag (tool, Space or middle button) glides and decays, gated by Enable Flick Panning || 2026-10-11 | minor | History snapshots: the camera button takes one, snapshot rows return to it as a new state, rename and delete it (#2966) || 2026-10-11 | minor | ⇧-drag a guide out of a ruler lands on the nearest ruler tick (#3770) |+| 2026-10-11 | minor | Layer and selection keys from Photoshop's shortcut set: ⌘, toggles, ⌘\, /, ⌘⌥2, ⌘⌥⌫, Tab rename-next, ⌥-click thumbnail to fit |