Fix feature creation at timeline end (#7620)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Frank
2026-10-27 21:17:39 +00:00
committed by GitHub
parent 83ac98ac76
commit 7fad8dbec0
2 changed files with 30 additions and 4 deletions
+5 -4
View File
@@ -3512,11 +3512,12 @@ impl Document {
match self.marker {
// 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);
Some(marker) => {
let position = marker.min(self.features.len());
self.features.insert(position, f);
self.marker = Some(position + 1);
}
_ => self.features.push(f),
None => self.features.push(f),
}
if let Some(group_id) = insertion_group {
let positions: std::collections::BTreeMap<u64, usize> =
+25
View File
@@ -54,6 +54,31 @@ fn repeat_is_refused_outside_the_app_and_changes_nothing() {
assert_eq!((spec.shortcut, spec.tab, spec.undoable), (Some("Shift+R"), "", false));
}
#[test]
fn creating_after_deleting_future_features_keeps_the_new_feature_active() {
let mut s = Session::default();
for (name, corner, size) in [("Base", [0, 0, 0], 10), ("Later1", [20, 0, 0], 2), ("Later2", [40, 0, 0], 3)] {
run(&mut s, "solid.box", json!({"name": name, "corner": corner, "length": size, "width": size, "height": size, "operation": "new"}));
}
run(&mut s, "timeline.roll_to", json!({"position": 1}));
run(&mut s, "solid.box", json!({"name": "Inserted", "corner": [60, 0, 0], "length": 4, "width": 4, "height": 4, "operation": "new"}));
assert_eq!(s.doc.features.iter().map(|feature| feature.name.as_str()).collect::<Vec<_>>(), ["Base", "Inserted", "Later1", "Later2"]);
assert_eq!(s.doc.marker, Some(2), "with later features, the new feature is inserted at the cursor");
run(&mut s, "timeline.delete", json!({"features": ["Later1", "Later2"]}));
assert_eq!(s.doc.features.len(), 2);
assert_eq!(s.doc.marker, Some(2), "the cursor is at the end after deleting all later features");
run(&mut s, "solid.box", json!({"name": "Appended", "corner": [80, 0, 0], "length": 5, "width": 5, "height": 5, "operation": "new"}));
assert_eq!(s.doc.features.iter().map(|feature| feature.name.as_str()).collect::<Vec<_>>(), ["Base", "Inserted", "Appended"]);
assert_eq!(s.doc.marker, Some(3), "the new feature advances the cursor to the end");
assert_eq!(s.model.state().bodies.len(), 3, "the appended feature is evaluated, not left in the future");
let volume = run(&mut s, "inspect.measure", json!({}))["total"]["volume_mm3"].as_f64().unwrap();
assert!((volume - 1189.0).abs() < 1e-6, "{volume}");
}
#[test]
fn g2_fillet_survives_edit_undo_and_reopen() {
use solidcraft_doc::{Document, FeatureKind, FilletStyle};