From cd253ee5d14e943edcc80d3716da5dffe6341fd7 Mon Sep 17 00:00:00 2001 From: Lcoding15 <125505497+Lcoding15@users.noreply.github.com> Date: Fri, 30 Oct 2026 11:39:42 +0100 Subject: [PATCH 1/5] Select: All selects the active artboard (#10258) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Select › All (Cmd+A) always filled the whole canvas, so on a document with several artboards the marching ants wrapped every board and the gaps between them. With the active layer on an artboard (the board itself or a layer inside it), Select All now selects that board, as Photoshop does; with no artboard involved it still selects the canvas. --- crates/engine/src/cmd.rs | 7 +++++- crates/engine/src/cmd/artboard_cmds/tests.rs | 23 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index 27c7ca3ce3..da4820ee0b 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -343,9 +343,14 @@ fn build() -> Vec { }), // Select cmd!("select.all", "All", ["Select"], Some("Cmd+A"), "{}", has_doc, |s, _| { + // With the active layer on an artboard (the board itself or a layer inside it), Select + // All selects that board, as Photoshop does; otherwise the whole canvas (#10258). + let active = s.active().and_then(|d| d.active_layer); s.edit("Select All", |doc, _| { + let board = active.and_then(|id| doc.artboard_of(id)).and_then(|id| doc.layer(id)).and_then(|l| l.artboard()).map(|a| a.rect); + let area = board.map_or(doc.bounds(), |r| r.intersect(&doc.bounds())); let mut m = Surface::new(photocraft_color::PixelFormat::GRAY8); - m.fill_rect(doc.bounds(), &[1.0]); + m.fill_rect(area, &[1.0]); doc.selection = Some(m); Ok(()) })?; diff --git a/crates/engine/src/cmd/artboard_cmds/tests.rs b/crates/engine/src/cmd/artboard_cmds/tests.rs index d21011a71b..4c3367cc3d 100644 --- a/crates/engine/src/cmd/artboard_cmds/tests.rs +++ b/crates/engine/src/cmd/artboard_cmds/tests.rs @@ -730,3 +730,26 @@ fn from_layers_defaults_are_the_selected_layers_size() { assert_eq!(from_layers_defaults(&s), Some(("Artboard 1".to_string(), [100, 80])), "an empty layer: the canvas"); assert_eq!(from_layers_defaults(&Session::new()), None); } + +/// #10258: with the active layer on an artboard (the board, or a layer inside it), Select All +/// selects that board, as Photoshop does; with no artboard involved, the whole canvas. +#[test] +fn select_all_selects_the_active_artboard() { + let mut s = session(8); + let first = board_with_square(&mut s); + let r = s.execute("layer.artboard.addBeside", json!({"layer": first.0, "side": "right"})).unwrap(); + let second = LayerId(r["layer"].as_u64().unwrap()); + let selected = |s: &Session, x: i32, y: i32| doc(s).selection.as_ref().map_or(0.0, |m| m.sample_channel(x, y, 0)); + let inner = doc(&s).layer(first).unwrap().children().and_then(|c| c.first()).map(|l| l.id).unwrap(); + for (layer, inside, outside) in [(second, (155, 15), (15, 15)), (first, (15, 15), (155, 15)), (inner, (15, 15), (155, 15))] { + s.execute("layer.select", json!({"layer": layer.0, "mode": "replace"})).unwrap(); + s.execute("select.all", json!({})).unwrap(); + assert_eq!((selected(&s, inside.0, inside.1), selected(&s, outside.0, outside.1)), (1.0, 0.0), "{layer:?}"); + assert_eq!(selected(&s, 100, 15), 0.0, "{layer:?}: not the gap between the boards"); + } + // A document without artboards selects its whole canvas. + let mut plain = session(8); + plain.execute("select.all", json!({})).unwrap(); + let (w, h) = (doc(&plain).size.width as i32, doc(&plain).size.height as i32); + assert_eq!((selected(&plain, 0, 0), selected(&plain, w - 1, h - 1)), (1.0, 1.0)); +} From ed7def22034ead07bd273141c14eb4c88b8867b4 Mon Sep 17 00:00:00 2001 From: Lcoding15 <125505497+Lcoding15@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:07:52 +0100 Subject: [PATCH 2/5] Select: All on a board the canvas no longer reaches selects the canvas (#10258) A board cropped off the canvas made an empty selection that blocked painting; it now selects the canvas. A test covers a board the canvas cuts off (clipped) and one cropped away entirely. --- crates/engine/src/cmd.rs | 4 +++- crates/engine/src/cmd/artboard_cmds/tests.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index da4820ee0b..e712c1eb37 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -348,7 +348,9 @@ fn build() -> Vec { let active = s.active().and_then(|d| d.active_layer); s.edit("Select All", |doc, _| { let board = active.and_then(|id| doc.artboard_of(id)).and_then(|id| doc.layer(id)).and_then(|l| l.artboard()).map(|a| a.rect); - let area = board.map_or(doc.bounds(), |r| r.intersect(&doc.bounds())); + // A board the canvas no longer reaches (cropped away) selects the canvas, never an + // empty selection that would block painting. + let area = board.map(|r| r.intersect(&doc.bounds())).filter(|r| !r.is_empty()).unwrap_or_else(|| doc.bounds()); let mut m = Surface::new(photocraft_color::PixelFormat::GRAY8); m.fill_rect(area, &[1.0]); doc.selection = Some(m); diff --git a/crates/engine/src/cmd/artboard_cmds/tests.rs b/crates/engine/src/cmd/artboard_cmds/tests.rs index 4c3367cc3d..1f738de01c 100644 --- a/crates/engine/src/cmd/artboard_cmds/tests.rs +++ b/crates/engine/src/cmd/artboard_cmds/tests.rs @@ -753,3 +753,22 @@ fn select_all_selects_the_active_artboard() { let (w, h) = (doc(&plain).size.width as i32, doc(&plain).size.height as i32); assert_eq!((selected(&plain, 0, 0), selected(&plain, w - 1, h - 1)), (1.0, 1.0)); } + +/// A board the canvas cuts off selects only the part inside it; a board cropped away entirely +/// selects the canvas, never an empty selection that would block painting. +#[test] +fn select_all_clips_the_active_artboard_to_the_canvas() { + let mut s = session(8); + let first = board_with_square(&mut s); + let r = s.execute("layer.artboard.addBeside", json!({"layer": first.0, "side": "right"})).unwrap(); + let second = LayerId(r["layer"].as_u64().unwrap()); + s.execute("image.canvasSize", json!({"width": 30, "height": 30, "anchor": "topLeft"})).unwrap(); + assert_eq!((doc(&s).size.width, doc(&s).size.height, board_rect(&s, first.0)), (30, 30, Rect::new(10, 10, 50, 50))); + let selected = |s: &Session, x: i32, y: i32| doc(s).selection.as_ref().map_or(0.0, |m| m.sample_channel(x, y, 0)); + s.execute("layer.select", json!({"layer": first.0, "mode": "replace"})).unwrap(); + s.execute("select.all", json!({})).unwrap(); + assert_eq!((selected(&s, 29, 29), selected(&s, 5, 5), selected(&s, 30, 30)), (1.0, 0.0, 0.0), "the board, clipped"); + s.execute("layer.select", json!({"layer": second.0, "mode": "replace"})).unwrap(); + s.execute("select.all", json!({})).unwrap(); + assert_eq!((selected(&s, 0, 0), selected(&s, 29, 29)), (1.0, 1.0), "a board off the canvas selects the canvas"); +} From 16a7dea959825a24e585c21a826edec7843e5a10 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 22:15:40 +0000 Subject: [PATCH 3/5] #10258: document the command table and the registry behind it The review's docstring-coverage check had nothing to read on the function this PR adds a command to. No behaviour change. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LymhVaGZCWwB9HNEbLzeMM --- crates/engine/src/cmd.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index e712c1eb37..fde38a2385 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -230,6 +230,7 @@ impl Registry { } } +/// The command registry, built on first use and shared for the rest of the process. fn registry() -> &'static Registry { static REGISTRY: std::sync::OnceLock = std::sync::OnceLock::new(); REGISTRY.get_or_init(|| Registry::new(build())) @@ -237,6 +238,7 @@ fn registry() -> &'static Registry { // ---------- the table ---------- +/// Every command this module owns, in menu order: the table the registry is built from once. #[allow(clippy::too_many_lines)] fn build() -> Vec { let mut v = vec![ From fd9f497029bb81d05e0d84e1f80e93fe24a8a9b6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 01:23:47 +0000 Subject: [PATCH 4/5] #10258: the nested-board case the review asks for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Of the four cases asked for, three were already covered: a board active, a layer inside one, and a document with no artboards. Nested boards are the fourth, and there are none to nest: `Document::artboard_of` reads the top-level ancestor, so an artboard is always a top-level group. The test says so where it matters. A group inside a board is given artboard data of its own — a PSD can carry that; the commands never make it — and `artboard_of` still names the outer board, which Select All then selects whole rather than taking the inner rect. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LymhVaGZCWwB9HNEbLzeMM --- crates/engine/src/cmd/artboard_cmds/tests.rs | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/engine/src/cmd/artboard_cmds/tests.rs b/crates/engine/src/cmd/artboard_cmds/tests.rs index 1f738de01c..1a3a72dc86 100644 --- a/crates/engine/src/cmd/artboard_cmds/tests.rs +++ b/crates/engine/src/cmd/artboard_cmds/tests.rs @@ -772,3 +772,32 @@ fn select_all_clips_the_active_artboard_to_the_canvas() { s.execute("select.all", json!({})).unwrap(); assert_eq!((selected(&s, 0, 0), selected(&s, 29, 29)), (1.0, 1.0), "a board off the canvas selects the canvas"); } + +/// #10258 review: an artboard is a top-level group, so there are no nested boards to choose +/// between — and a group carrying artboard data *inside* a board (a PSD can hold one; the +/// commands never make one) changes nothing: `Document::artboard_of` names the top-level board, +/// which is the one Select All takes. +#[test] +fn select_all_takes_the_top_level_board_even_with_a_board_inside_one() { + let mut s = session(8); + let board = board_with_square(&mut s); + let child = doc(&s).layer(board).and_then(|l| l.children()).and_then(|c| c.first()).map(|l| l.id).expect("the board holds the square"); + s.execute("layer.select", json!({"layer": child.0, "mode": "replace"})).unwrap(); + let inner = LayerId(s.execute("layer.groupLayers", json!({})).unwrap()["layer"].as_u64().unwrap()); + // Give that inner group a board's own rect: a smaller one, well inside the outer board. + s.edit("nest", |doc, _| { + let g = doc.layer_mut(inner).ok_or(EngineError::NoLayer(inner))?; + if let photocraft_doc::LayerContent::Group(grp) = &mut g.content { + grp.artboard = Some(photocraft_doc::Artboard { rect: Rect::new(14, 14, 22, 22), background: Default::default(), preset: String::new() }); + } + Ok(()) + }) + .unwrap(); + assert_eq!(doc(&s).artboard_of(inner), Some(board), "the top-level board, not the nested one"); + let selected = |s: &Session, x: i32, y: i32| doc(s).selection.as_ref().map_or(0.0, |m| m.sample_channel(x, y, 0)); + s.execute("layer.select", json!({"layer": inner.0, "mode": "replace"})).unwrap(); + s.execute("select.all", json!({})).unwrap(); + // The whole 40x40 board at (10, 10), not the inner 8x8 rect. + assert_eq!((selected(&s, 12, 12), selected(&s, 45, 45)), (1.0, 1.0), "the outer board is selected whole"); + assert_eq!(selected(&s, 5, 5), 0.0, "and nothing outside it"); +} From fc5a6e561fd620aab63c62ece0547543bf659a0f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 19:40:34 +0000 Subject: [PATCH 5/5] #10258: the square in a nested group selects the outer board Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01GbuSKAS2k5248LGFEapMUR --- crates/engine/src/cmd/artboard_cmds/tests.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/engine/src/cmd/artboard_cmds/tests.rs b/crates/engine/src/cmd/artboard_cmds/tests.rs index 1358e82ab0..fe3c6b116d 100644 --- a/crates/engine/src/cmd/artboard_cmds/tests.rs +++ b/crates/engine/src/cmd/artboard_cmds/tests.rs @@ -910,4 +910,9 @@ fn select_all_takes_the_top_level_board_even_with_a_board_inside_one() { // The whole 40x40 board at (10, 10), not the inner 8x8 rect. assert_eq!((selected(&s, 12, 12), selected(&s, 45, 45)), (1.0, 1.0), "the outer board is selected whole"); assert_eq!(selected(&s, 5, 5), 0.0, "and nothing outside it"); + // CodeRabbit on #10306: so does the square inside the nested group. + s.execute("select.deselect", json!({})).unwrap(); + s.execute("layer.select", json!({"layer": child.0, "mode": "replace"})).unwrap(); + s.execute("select.all", json!({})).unwrap(); + assert_eq!((selected(&s, 12, 12), selected(&s, 45, 45), selected(&s, 5, 5)), (1.0, 1.0, 0.0), "the square in the nested group takes the outer board"); }