diff --git a/crates/engine/src/cmds_raw.rs b/crates/engine/src/cmds_raw.rs index 093cd8d6..8105d009 100644 --- a/crates/engine/src/cmds_raw.rs +++ b/crates/engine/src/cmds_raw.rs @@ -46,7 +46,7 @@ pub fn specs() -> Vec { "Select Parts", "", None, - "{x0, y0, x1, y1, add?: bool} the marquee, on every visible, unlocked layer: the parts of raw fills and strokes under the rectangle (cut at its edges, per layer) and the objects wholly inside it", + "{x0, y0, x1, y1, add?: bool} the marquee, on every visible, unlocked layer: the parts of raw fills and strokes under the rectangle (cut at its edges, per layer) and the objects it touches", true, select_rect, ), @@ -631,7 +631,7 @@ fn on_editable_key(s: &Session) -> bool { } /// The marquee (ADR 0041, 0044): on every visible, unlocked layer, the parts of raw shapes under -/// the rectangle (cut at its edges) and the objects wholly inside it. +/// the rectangle (cut at its edges) and the objects it touches (#522). fn select_rect(s: &mut Session, p: &Value) -> Result { let a = Vec2::new(f32_req(p, "x0")?, f32_req(p, "y0")?); let b = Vec2::new(f32_req(p, "x1")?, f32_req(p, "y1")?); @@ -643,8 +643,8 @@ fn select_rect(s: &mut Session, p: &Value) -> Result { if r.width() <= 0.0 || r.height() <= 0.0 { return Ok(json!({"selected": s.selection.id_list(), "cut": 0})); } - // What each layer has under the marquee, from one display list: wholly inside, or (raw - // shapes) partly. + // What each layer has under the marquee, from one display list: taken whole, or (raw + // shapes partly under it) cut. let mut found: Vec<(LayerId, Vec, Vec)> = Vec::new(); let layers: Vec = s.timeline().layers.iter().map(|l| l.id).filter(|l| s.gathers(*l)).collect(); for l in layers { @@ -654,9 +654,11 @@ fn select_rect(s: &mut Session, p: &Value) -> Result { if bounds.is_empty() || bounds.intersect(&r).is_empty() { continue; } - if contains(&r, &bounds) { + // An object (instance, group, drawing object, text, bitmap) the marquee touches is + // taken whole (#522); a raw shape partly under it is cut at its edges. + if contains(&r, &bounds) || mergeable(&e).is_none() { picked.push(e.id); - } else if mergeable(&e).is_some() { + } else { partial.push(e.id); } } @@ -688,7 +690,8 @@ fn select_rect(s: &mut Session, p: &Value) -> Result { } /// The marquee on the active layer: raw shapes partly under `r` are cut at its edges and the -/// parts inside are selected, the rest stay as they are; `picked` (wholly inside) are selected. +/// parts inside are selected, the rest stay as they are; `picked` (objects it touches, raw shapes +/// wholly inside) are selected. /// How many pieces it cut, each piece with the shape it came from, and the pieces inside. fn marquee_layer(s: &mut Session, r: &Rect, mut picked: Vec, partial: &[ElementId]) -> Result<(usize, CutOrigin, Vec)> { let here = s.layer; diff --git a/crates/engine/src/selection_tests.rs b/crates/engine/src/selection_tests.rs index ecc4ce99..9336d99f 100644 --- a/crates/engine/src/selection_tests.rs +++ b/crates/engine/src/selection_tests.rs @@ -658,3 +658,22 @@ fn break_apart_twice_on_text_ends_in_raw_shapes() { let err = s.execute("modify.break_apart", &json!({})).unwrap_err().to_string(); assert!(err.contains("raw shapes already"), "{err}"); } + +/// #522: a marquee that touches part of a symbol instance or a group selects it whole, as it +/// does a drawing object; one it misses stays unselected. +#[test] +fn a_marquee_takes_the_instances_and_groups_it_touches() { + let mut s = Session::default(); + run(&mut s, "draw.ellipse", json!({"x": 0, "y": 0, "w": 100, "h": 100, "stroke": null, "object": true})); + run(&mut s, "modify.convert_to_symbol", json!({"name": "Dot"})); + run(&mut s, "edit.deselect", json!({})); + run(&mut s, "draw.rect", json!({"x": 200, "y": 0, "w": 100, "h": 100, "stroke": null, "object": true})); + run(&mut s, "modify.group", json!({})); + run(&mut s, "edit.deselect", json!({})); + run(&mut s, "draw.rect", json!({"x": 400, "y": 0, "w": 100, "h": 100, "stroke": null, "object": true})); + run(&mut s, "edit.deselect", json!({})); + // Across the lower halves of the first two only. + run(&mut s, "raw.select_rect", json!({"x0": -10, "y0": 50, "x1": 350, "y1": 150})); + let kinds: Vec<&'static str> = s.selected_elements().iter().map(|(_, e)| match e.kind { ElementKind::Symbol { .. } => "symbol", ElementKind::Group { .. } => "group", _ => "other" }).collect(); + assert!(kinds.contains(&"symbol") && kinds.contains(&"group") && kinds.len() == 2, "{kinds:?}"); +} diff --git a/docs/guide/drawing.md b/docs/guide/drawing.md index 80147e21..78d7c583 100644 --- a/docs/guide/drawing.md +++ b/docs/guide/drawing.md @@ -92,7 +92,8 @@ With the **Selection** tool (**V**) on merged drawing: * **Double-click** a line to select every line joined to it, or a fill to select the fill and its outline. * **Drag a marquee** to select the parts of fills and lines under it, cut at the marquee's - edges, plus any objects wholly inside it. **Shift** adds more. If you click away without + edges, plus any objects it touches (symbol instances, groups, drawing objects, text and + bitmaps are taken whole). **Shift** adds more. If you click away without changing anything, the drawing is whole again. * **Drag an unselected line** or the edge of a fill to **bend** it into a curve through the pointer. Its ends stay put, and a straight edge bends into one even arc wherever you grab it. diff --git a/docs/guide/reference/commands.md b/docs/guide/reference/commands.md index 3068d543..3dd28080 100644 --- a/docs/guide/reference/commands.md +++ b/docs/guide/reference/commands.md @@ -622,7 +622,7 @@ These commands have no menu item: the panels, the stage and the timeline use the - **Move Point** `raw.move_point` · changes the document Parameters: ``{x, y, to_x, to_y, with?: [[x, y], ..], points?: [[id, cmd], ..], snap?, slop?, merge?: bool} moves the corner or end at (x, y), with every raw shape that shares it, to (to_x, to_y), snapped within `snap` to points, lines and fill edges (while Snap to Objects is on); the anchors at `with` move by as much; returns the points to pass on while a drag goes on`` - **Select Parts** `raw.select_rect` · changes the document - Parameters: `{x0, y0, x1, y1, add?: bool} the marquee, on every visible, unlocked layer: the parts of raw fills and strokes under the rectangle (cut at its edges, per layer) and the objects wholly inside it` + Parameters: `{x0, y0, x1, y1, add?: bool} the marquee, on every visible, unlocked layer: the parts of raw fills and strokes under the rectangle (cut at its edges, per layer) and the objects it touches` - **Merge Shapes** `raw.merge` · changes the document Parameters: `{ids?: [..]} the raw shapes (default: the selection) merge again with the raw shapes they touch, in place` - **Selection Tool Target** `raw.hit` diff --git a/src/stage.rs b/src/stage.rs index 704c8ca8..7efb0247 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -772,7 +772,7 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { Drag::MultiMarquee { start, cur } => crate::onion::marquee(app, start, cur, shift), Drag::Marquee { start, cur } => { // The parts of raw fills and strokes under it, cut at its edges, and the objects - // wholly inside it (ADR 0041). + // it touches (ADR 0041, #522). app.run("raw.select_rect", json!({"x0": start.x, "y0": start.y, "x1": cur.x, "y1": cur.y, "add": shift})); } Drag::Shape { start, cur } => create_shape(app, start, cur),