diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 65ea837527..0edf9f9a93 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -476,6 +476,7 @@ impl Session { plane_targets: self.prefs.perspective_widget.targets(), precise_cursors: self.precise_cursors(), global_edit: st.global_edit.as_ref().map_or(&[], |g| g.members.as_slice()), + interaction_doc: st.interaction.as_ref().map(|it| &*it.doc), }; let tool = &mut self.tool; match crate::guard::catch_panic(|| f(tool.as_mut(), &cx)) { diff --git a/crates/engine/tests/it/dimensions.rs b/crates/engine/tests/it/dimensions.rs index c73fa8d0a6..28417f031a 100644 --- a/crates/engine/tests/it/dimensions.rs +++ b/crates/engine/tests/it/dimensions.rs @@ -2080,19 +2080,36 @@ fn a_dimension_of_the_same_points_lines_up_and_the_line_follows_the_pointer() { assert_eq!(recipe(&s, id).line_ends(), (pt(200.0, 186.0), pt(300.0, 186.0))); } -/// With Real-time Drawing off, a dimension hidden, locked or deleted by a command while another is -/// placed is no longer a level: no guide runs along its level. +/// A command that moves or hides a dimension while another is placed (Real-time Drawing on) does +/// not leave the placed dimension on a level the committed document does not have: committed with +/// its line near the other dimension's line as the document has it then, it is on that level, and +/// otherwise at the pointer. #[test] -fn a_dimension_hidden_locked_or_deleted_while_another_is_placed_is_no_longer_a_level() { +fn a_dimension_placed_after_a_command_lines_up_with_the_committed_document() { let plain = ViewInfo::default(); - for cmd in ["object.hide", "object.lock", "edit.clear"] { + for (cmd, params, y) in [("dimension.update", json!({"offset": -10.0}), 192.0), ("object.hide", json!({}), 172.0)] { let (mut s, first) = level_start(plain); - run(&mut s, "prefs.set", json!({"key": "realTimeDrawing", "value": false})); - linear_click(&mut s, plain, 200.0, 200.0); - linear_click(&mut s, plain, 300.0, 200.0); - assert!(!guide_lines(&mut s, plain, 250.0, 172.5).is_empty(), "{cmd}: on the level before"); - run(&mut s, cmd, json!({"ids": [first]})); - assert!(guide_lines(&mut s, plain, 250.0, 172.5).is_empty(), "{cmd}: no level after"); + run(&mut s, "prefs.set", json!({"key": "realTimeDrawing", "value": true})); + // The bottom edge dragged out onto the level of the first line. + for (kind, y) in [(PointerKind::Move, 300.0), (PointerKind::Down, 300.0), (PointerKind::Drag, 240.0), (PointerKind::Drag, 172.0)] { + s.pointer(&PointerEvent::new(kind, 160.0, y), plain).unwrap(); + } + let mut params = params; + params["ids"] = json!([first]); + run(&mut s, cmd, params); + if cmd == "dimension.update" { + assert_eq!(recipe(&s, first).line_ends().0.y, 190.0, "moved before the release"); + } + // Released without a drag in between: the release places the dimension. + s.pointer(&PointerEvent::new(PointerKind::Up, 160.0, y), plain).unwrap(); + let placed = s.doc().unwrap().selection.objects[0].0; + assert_ne!(placed, first, "{cmd}: a new dimension"); + let reference = s.doc().unwrap().doc.node(NodeId(first)).map(|n| (n.visible, recipe(&s, first).line_ends().0.y)); + let expected = match reference { + Some((true, level)) if (level - y).abs() <= 4.0 => level, + _ => y, + }; + assert_eq!(recipe(&s, placed).line_ends().0.y, expected, "{cmd}: the other dimension is {reference:?}"); } } diff --git a/crates/tools/src/context.rs b/crates/tools/src/context.rs index 0946ad7a2d..21969a4f2e 100644 --- a/crates/tools/src/context.rs +++ b/crates/tools/src/context.rs @@ -350,6 +350,10 @@ pub struct ToolContext<'a> { /// The objects of the Global Edit in progress (Select › Start Global Edit), the one it started /// from first, each with its transform; empty while Global Edit is off. pub global_edit: &'a [(NodeId, vectorcraft_geom::Affine)], + /// While an interaction is in progress: the document as it was when the interaction began, + /// which each preview of the interaction replaces the document with before it applies. None + /// outside an interaction. + pub interaction_doc: Option<&'a Document>, } impl ToolContext<'_> { diff --git a/crates/tools/src/dimension.rs b/crates/tools/src/dimension.rs index 9d22d1f03e..a44a82a255 100644 --- a/crates/tools/src/dimension.rs +++ b/crates/tools/src/dimension.rs @@ -484,10 +484,10 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> { /// The line of a linear dimension already drawn: its ends and its direction. type DimensionLine = ((Point, Point), Vec2); -/// The lines of the visible, unlocked linear dimensions in the document, except the preview of the +/// The lines of the visible, unlocked linear dimensions in `doc`, except the preview of the /// dimension being placed: a dimension with the id `preview.0` that measures the points /// `preview.1`. Bounded work, as in [`on_dimensions`]. -fn dimension_lines(cx: &ToolContext, preview: (u64, [Point; 2])) -> Vec { +fn dimension_lines(doc: &vectorcraft_doc::Document, preview: (u64, [Point; 2])) -> Vec { fn visit(n: &Node, preview: (u64, [Point; 2]), budget: &mut usize, out: &mut Vec) { let is_preview = n.id.0 == preview.0 && n.extras().dimension.as_ref().is_some_and(|d| d.a.distance(preview.1[0]) < 1e-9 && d.b.distance(preview.1[1]) < 1e-9); @@ -509,7 +509,7 @@ fn dimension_lines(cx: &ToolContext, preview: (u64, [Point; 2])) -> Vec