Quick Selection: a frame active keeps reading the composite

A frame is a group too, but the reference application was not measured
with one active, so it keeps today's behaviour, as an artboard does.
This commit is contained in:
ljkx committed 2026-11-13 11:43:08 +01:00
1 parent 9ff5aa8565
commit bf4b20b025
2 files changed
+17 -11

No files matched your search

+6 -4
View File
@@ -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<R>(s: &Session, all_layers: bool, f: impl FnOnce(&dyn Sampler, &Document) -> R) -> Result<R> {
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) }
}
@@ -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);
}
}