diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index f04a25b06..1a9fcd0d8 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -3505,7 +3505,9 @@ impl Document { let id = f.id; let insertion_group = self.marker.and_then(|marker| self.timeline_group_at_insertion(marker)); match self.marker { - Some(m) if m < self.features.len() => { + // A marker right after the last feature moves on past a feature added there, or the + // new feature would be added rolled back (#7741). + Some(m) if m <= self.features.len() => { self.features.insert(m, f); self.marker = Some(m + 1); } diff --git a/crates/doc/src/tests.rs b/crates/doc/src/tests.rs index 0c521ec14..9f338af0c 100644 --- a/crates/doc/src/tests.rs +++ b/crates/doc/src/tests.rs @@ -562,6 +562,21 @@ fn feature_inserted_at_a_marker_inside_a_timeline_folder_joins_it() { assert!(Document::from_json(&doc.to_json()).is_ok(), "the inserted feature must leave a reopenable design"); } +/// A marker after the last feature leaves every feature active, as no marker does, so a feature +/// added then is active too, not added rolled back (#7741: editing the last feature from the +/// History runs its command with the marker there). +#[test] +fn feature_added_with_the_marker_at_the_end_is_active() { + let mut doc = Document::new("marker at the end"); + let first = doc.add_feature(FeatureKind::Sketch { plane: PlaneRef::Origin { name: "XY".into() }, sketch: Sketch::new() }, Some("First")).unwrap(); + doc.marker = Some(1); + + let added = doc.add_feature(FeatureKind::Sketch { plane: PlaneRef::Origin { name: "XY".into() }, sketch: Sketch::new() }, Some("Added")).unwrap(); + + assert_eq!(doc.features.iter().map(|feature| feature.id).collect::>(), vec![first, added]); + assert_eq!(doc.marker, Some(2), "the marker stays after the last feature"); +} + /// A construction plane that is its own side resolves through the model and back into the /// document. The depth count has to survive that hop, or the recursion overflows the stack and /// aborts the process, which no panic guard can intercept. diff --git a/crates/engine/src/cmd/solid_move_copy_tests.rs b/crates/engine/src/cmd/solid_move_copy_tests.rs index 7c057c386..793817540 100644 --- a/crates/engine/src/cmd/solid_move_copy_tests.rs +++ b/crates/engine/src/cmd/solid_move_copy_tests.rs @@ -89,6 +89,24 @@ fn a_copied_body_keeps_the_appearance_of_the_body_it_came_from() { assert_eq!(s.doc.appearances.bodies.get(©), Some(&source), "the copy must keep the appearance of the body it came from"); } +/// Editing a copying Move from the History redefines it on a scratch session, where the old Move +/// is still in the timeline as a suppressed placeholder (#7741). +#[test] +fn a_copying_move_can_be_edited_from_the_history() { + let mut s = Session::default(); + cube20(&mut s, "Cube"); + run(&mut s, "appearance.assign", json!({"bodies": ["Cube"], "appearance": "ABS - Blue"})); + let reply = run(&mut s, "solid.move", json!({"bodies": ["Cube"], "translate": [30, 0, 0], "copy": true})); + let feature = reply["feature"].clone(); + let copy = created(&reply); + let edit = json!({"feature": feature, "command": "solid.move", "params": {"bodies": ["Cube"], "translate": [40, 0, 0], "copy": true}}); + s.execute("timeline.redefine", &edit).expect("editing a copying move must keep copying"); + assert_eq!(s.model.state().bodies.len(), 2, "the edited move still makes one copy"); + assert_eq!(copy_of(&s, "Cube", Vec3::new(40.0, 0.0, 0.0)), copy, "the copy keeps its name and moves to the new place"); + let source = s.doc.appearances.bodies.get("Cube").expect("the source body keeps its look").clone(); + assert_eq!(s.doc.appearances.bodies.get(©), Some(&source), "the edited copy keeps the look of the body it came from"); +} + #[test] fn a_copied_body_keeps_the_material_of_the_body_it_came_from() { let mut s = Session::default();