diff --git a/crates/engine/src/cmd/smartselect_cmds.rs b/crates/engine/src/cmd/smartselect_cmds.rs index 3702375817..941540e6f9 100644 --- a/crates/engine/src/cmd/smartselect_cmds.rs +++ b/crates/engine/src/cmd/smartselect_cmds.rs @@ -78,12 +78,14 @@ impl Sampler for FlatSampler { } } -/// Runs `f` with Quick Selection's sampler: [`with_sampler`]'s, except that with a group (not an -/// artboard) active and Sample All Layers off it reads a flat area, so a click selects only the -/// brush disc instead of the composite's shapes, as the reference application does (#12933). +/// Runs `f` with Quick Selection's sampler: [`with_sampler`]'s, except that with a group active +/// and Sample All Layers off it reads a flat area, so a click selects only the brush disc instead +/// of the composite's shapes, as the reference application does (#12933). Artboards and frames, +/// groups too but not measured, keep reading the composite. fn with_quick_sampler(s: &Session, all_layers: bool, f: impl FnOnce(&dyn Sampler, &Document) -> R) -> Result { let d = s.active().ok_or(EngineError::NoDocument)?; - let group = d.active_layer.and_then(|id| d.doc.layer(id)).is_some_and(|l| matches!(&l.content, LayerContent::Group(g) if g.artboard.is_none())); + let plain_group = |l: &Layer| l.frame.is_none() && matches!(&l.content, LayerContent::Group(g) if g.artboard.is_none()); + let group = d.active_layer.and_then(|id| d.doc.layer(id)).is_some_and(plain_group); if group && !all_layers { Ok(f(&FlatSampler, &d.doc)) } else { with_sampler(s, all_layers, f) } } diff --git a/crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs b/crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs index b276a27ea7..94edd217b3 100644 --- a/crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs +++ b/crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs @@ -107,11 +107,15 @@ fn an_adjustment_layer_reads_the_composite() { } #[test] -fn an_artboard_still_reads_the_composite() { - // Not measured for an artboard, so it keeps reading the composite. - let mut s = issue_document(); - s.execute("layer.new.artboard", json!({"rect": [700, 500, 50, 50]})).unwrap(); - assert_eq!(active_kind(&s), "Group"); - click(&mut s, RED2_CLICK, false); - assert_selects_rect(&s, [500, 100, 600, 200], 3); +fn an_artboard_or_a_frame_still_reads_the_composite() { + // Not measured for these groups, so they keep reading the composite. + for (cmd, params) in + [("layer.new.artboard", json!({"rect": [700, 500, 50, 50]})), ("layer.new.frame", json!({"x": 700, "y": 500, "width": 50, "height": 50}))] + { + let mut s = issue_document(); + s.execute(cmd, params).unwrap(); + assert_eq!(active_kind(&s), "Group", "{cmd}"); + click(&mut s, RED2_CLICK, false); + assert_selects_rect(&s, [500, 100, 600, 200], 3); + } }