From 8cdea53cedbf0c6f55d11c0bee522a9f43f142cc Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 11:50:37 +0000 Subject: [PATCH] Carry #1745: Current & Below keeps an active group's own contents Document::walk lists a group before its children, so hiding everything after the active layer hid a group's own layers and sampled transparent. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UHgFEHEsefoQoBParH47JA --- crates/engine/src/sample_cmds.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/sample_cmds.rs b/crates/engine/src/sample_cmds.rs index 3c20a6dc525..b44efb7ac30 100644 --- a/crates/engine/src/sample_cmds.rs +++ b/crates/engine/src/sample_cmds.rs @@ -140,9 +140,11 @@ fn sampled_document(doc: &Document, active: Option, which: SampleLayers let mut copy = doc.clone(); let walk: Vec<(Vec, LayerId, bool)> = doc.walk().into_iter().map(|(p, _, l)| (p, l.id, matches!(l.content, LayerContent::Adjustment(_)))).collect(); if matches!(which, SampleLayers::CurrentAndBelow | SampleLayers::CurrentAndBelowNoAdjustments) { - // Everything composited after (above) the active layer in the bottom-to-top walk. + // Everything composited after (above) the active layer in the bottom-to-top walk, except + // its own contents: the walk lists a group before its children. let pos = walk.iter().position(|(_, id, _)| Some(*id) == active)?; - for (path, _, _) in walk.get(pos + 1..).unwrap_or_default() { + let own = walk.get(pos).map(|(p, _, _)| p.clone()).unwrap_or_default(); + for (path, _, _) in walk.get(pos + 1..).unwrap_or_default().iter().filter(|(p, _, _)| !p.starts_with(&own)) { if let Some(l) = copy.layer_at_mut(path) { l.visible = false; } @@ -377,6 +379,21 @@ mod tests { } } + #[test] + fn current_and_below_keeps_an_active_groups_contents() { + // A white background and a group holding a red layer; the group is the active layer. + let mut d = doc(3, 3, ColorMode::Rgb, SampleType::U8, |_, _| [1.0; 4]); + let mut red = Layer::raster("red", d.pixel_format()); + red.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 3, 3), &[1.0, 0.0, 0.0, 1.0]); + let group = Layer::group("group", vec![red]); + let gid = group.id; + d.layers.push(group); + for which in [SampleLayers::CurrentAndBelow, SampleLayers::CurrentAndBelowNoAdjustments] { + let c = sample_color(&d, Some(gid), 1.5, 1.5, 1, which); + assert!(close(c, [1.0, 0.0, 0.0, 1.0], 1.5 / 255.0), "{which:?}: {c:?}"); + } + } + #[test] fn sample_layers_choose_what_is_averaged() { // Background white; a red 3x3 layer in the middle; an Invert adjustment on top.