diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 95fdf695b0..73c92877e9 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -463,17 +463,22 @@ fn target(s: &mut Session, p: &Value) -> Result { /// `layer.target` with `range`, a Shift-click range of target circles: the art of every listed row /// that is visible, unlocked and inside the isolated group is selected, or added to the selection -/// with `add`. Nothing is targeted, and the highlighted rows and the current layer stay. +/// with `add`. Nothing is targeted, and the highlighted rows stay. The current layer follows the +/// selection, as with any selection change ([`Session::select`]). fn target_range(s: &mut Session, p: &Value, mut ids: Vec) -> Result { const C: &str = "layer.target"; ids.truncate(MAX_ROWS); let add = switch_or(p, "add", false, C)?; - let st = s.doc()?; - ids.retain(|id| st.doc.node(*id).is_some() && st.doc.is_editable(*id) && in_isolation(&st.doc, st.isolation, *id)); + let rows = { + let st = s.doc()?; + // Measures the locked artboards once for every row, not once per row. + let editable = st.doc.editable(); + ids.retain(|id| st.doc.node(*id).is_some() && editable(*id) && in_isolation(&st.doc, st.isolation, *id)); + st.layer_rows.clone() + }; if ids.is_empty() { return Err(bad(C, "no row in the range is visible, unlocked and inside the isolated group")); } - let rows = st.layer_rows.clone(); s.select(|d, sel| sel.target_range(d, &ids, add))?; let st = s.doc_mut()?; // Targeting doesn't change which rows are highlighted. diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index c80dccb87a..965534b94e 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -211,6 +211,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { ui.data_mut(|d| { if before.is_some() { d.remove::<(u64, String)>(rename_id()); + // So is the target circles' Shift-click anchor: it could name another row here. + d.remove::(key("target-anchor")); } d.insert_temp(shown_doc, st.uid); }); diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index 37c4bd6238..553ff2df61 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -447,6 +447,28 @@ fn shift_clicking_a_target_circle_selects_a_range_of_rows() { assert_eq!(selected(&app), (None, vec![a, c3])); } +/// The Shift-click anchor of the target circles belongs to the document it was clicked in: node +/// ids are per document, so in another document a Shift-click with no circle clicked there yet +/// targets only its own row, never a range from a row that has the old anchor's id. +#[test] +fn the_target_circle_anchor_does_not_carry_over_to_another_document() { + let (mut app, _, [a, _]) = two_rects(); + let ctx = egui::Context::default(); + let (c, _) = frame(&mut app, &ctx, vec![], false); + // Rows top down: the layer, b, a. The anchor is a. + click_with(&mut app, &ctx, c[2], egui::Modifiers::NONE); + let run = |app: &mut VectorcraftApp, id: &str, p: serde_json::Value| app.session.execute(id, &p).unwrap(); + run(&mut app, "file.new", json!({"width": 200, "height": 200})); + let a2 = NodeId(run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50}))["id"].as_u64().unwrap()); + let b2 = NodeId(run(&mut app, "shape.rectangle", json!({"x": 60, "y": 0, "width": 50, "height": 50}))["id"].as_u64().unwrap()); + run(&mut app, "select.none", json!({})); + assert_eq!(a2, a, "the new document reuses the old anchor's id, so a stale anchor would find a row"); + let (c, _) = frame(&mut app, &ctx, vec![], false); + click_with(&mut app, &ctx, c[1], egui::Modifiers::SHIFT); + let st = app.session.active().unwrap(); + assert_eq!((st.selection.target, st.selection.objects.clone()), (Some(b2), vec![b2])); +} + #[test] fn dragging_a_target_circle_moves_or_copies_the_appearance() { let (mut app, layer, [a, b]) = two_rects();