SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Timeline: delete the selected features, Shift+click ranges, delete after the history marker (#5005) (#5006)
Daniel2f55a39c9c83
diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex 9cc32df7c9..79c32e881b 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -1402,6 +1402,9 @@"thread.designation": "Designation","thread.iso_metric": "ISO metric","thread.select_size": "Select size",+ "timeline.delete_after_marker_one": "Delete 1 Feature After History Marker",+ "timeline.delete_after_marker_other": "Delete {count} Features After History Marker",+ "timeline.delete_many": "Delete {count} Selected Features","timeline.group": "New Feature Folder","timeline.move_many": "Move Timeline Items","timeline.move_to_group": "Move Features to Folder",diff --git a/assets/locales/ja.json b/assets/locales/ja.jsonindex ca0da91b74..86af4e4458 100644--- a/assets/locales/ja.json+++ b/assets/locales/ja.json@@ -1402,6 +1402,9 @@"thread.designation": "ねじの呼び","thread.iso_metric": "ISOメートルねじ","thread.select_size": "サイズを選択",+ "timeline.delete_after_marker_one": "履歴マーカー以降の 1 個のフィーチャーを削除",+ "timeline.delete_after_marker_other": "履歴マーカー以降の {count} 個のフィーチャーを削除",+ "timeline.delete_many": "選択した {count} 個のフィーチャーを削除","timeline.group": "フィーチャーフォルダを新規作成","timeline.move_many": "タイムライン項目を移動","timeline.move_to_group": "フィーチャーをフォルダへ移動",diff --git a/assets/locales/pl.json b/assets/locales/pl.jsonindex 13f4c2d9a9..430a22933a 100644--- a/assets/locales/pl.json+++ b/assets/locales/pl.json@@ -1284,6 +1284,9 @@"thread.designation": "Oznaczenie","thread.iso_metric": "Metryczny ISO","thread.select_size": "Wybierz rozmiar",+ "timeline.delete_after_marker_one": "Usuń 1 funkcję za znacznikiem historii",+ "timeline.delete_after_marker_other": "Usuń funkcje za znacznikiem historii: {count}",+ "timeline.delete_many": "Usuń zaznaczone funkcje: {count}","timeline.group": "Nowy folder funkcji","timeline.move_many": "Przenieś elementy osi czasu","timeline.move_to_group": "Przenieś funkcje do folderu",diff --git a/assets/locales/zh.json b/assets/locales/zh.jsonindex 678d56debd..409307fe80 100644--- a/assets/locales/zh.json+++ b/assets/locales/zh.json@@ -1402,6 +1402,9 @@"thread.designation": "螺纹标记","thread.iso_metric": "ISO 公制","thread.select_size": "选择尺寸",+ "timeline.delete_after_marker_one": "删除历史标记之后的 1 个特征",+ "timeline.delete_after_marker_other": "删除历史标记之后的 {count} 个特征",+ "timeline.delete_many": "删除所选的 {count} 个特征","timeline.group": "新建特征文件夹","timeline.move_many": "移动时间线项目","timeline.move_to_group": "将特征移至文件夹",diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex 9002faa9ce..6a418cda0e 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -174,12 +174,22 @@ pub(crate) fn delete_features(app: &mut SolveApp, ids: Vec<u64>) {/// [`delete_features`] once each feature's `timeline.dependents` report is in.pub(crate) fn delete_checked_features(app: &mut SolveApp, ids: Vec<u64>, reports: &[Value]) {+ // Each report is about one feature alone, so it names the others being deleted too: those+ // go anyway and are left out of the confirmation.+ let deleting: Vec<&str> = ids.iter().filter_map(|id| app.session.doc.feature(*id)).map(|f| f.name.as_str()).collect();let mut with = std::collections::BTreeSet::new();let mut fail = std::collections::BTreeSet::new();for deps in reports {for (key, output) in [("deleted_with_it", &mut with), ("would_fail", &mut fail)] {- output- .extend(deps.get(key).and_then(|value| value.as_array()).into_iter().flatten().filter_map(|value| value.as_str().map(String::from)));+ output.extend(+ deps.get(key)+ .and_then(|value| value.as_array())+ .into_iter()+ .flatten()+ .filter_map(|value| value.as_str())+ .filter(|name| !deleting.contains(name))+ .map(String::from),+ );}}if with.is_empty() && fail.is_empty() {@@ -202,17 +212,45 @@ pub(crate) fn selected_feature_ids(app: &SolveApp) -> Vec<u64> {.collect()}-/// What Copy in a feature's menu copies: the selected features when the right-clicked one is-/// among them, else that feature alone.-pub(crate) fn copy_targets(app: &SolveApp, id: u64) -> Vec<u64> {+/// What Copy and Delete in a feature's menu act on: the selected features when the+/// right-clicked one is among them, else that feature alone.+pub(crate) fn menu_targets(app: &SolveApp, id: u64) -> Vec<u64> {let selected = selected_feature_ids(app);if selected.contains(&id) { selected } else { vec![id] }}+/// The features from timeline position `from` to the end.+fn features_from(app: &SolveApp, from: usize) -> Vec<u64> {+ app.session.doc.features.iter().skip(from).map(|f| f.id).collect()+}++/// In the menu of a feature after the history marker (feature `id` at timeline position+/// `index`): delete every feature after the marker, labelled with how many, in one delete+/// through [`delete_features`] so the confirmation still lists what would fail. Not offered+/// before the marker, nor when the menu acts on several selected features: an entry that acts+/// partly on the selection and partly beyond it is hard to read.+pub(crate) fn delete_after_marker_button(app: &mut SolveApp, ui: &mut egui::Ui, id: u64, index: usize, marker: usize) {+ if index < marker || menu_targets(app, id).len() > 1 {+ return;+ }+ let ids = features_from(app, marker);+ let key = if ids.len() == 1 { "timeline.delete_after_marker_one" } else { "timeline.delete_after_marker_other" };+ let label = crate::i18n::format(key, &[("count", &ids.len().to_string())]);+ if crate::context_menu::button(ui, &label, "delete").clicked() {+ delete_features(app, ids);+ ui.close();+ }+}++/// The timeline anchor of a feature: the last one clicked, where a Shift+click range starts.+pub(crate) fn anchor_key(id: u64) -> String {+ format!("f:{id}")+}+/// Copy and Paste in a feature's timeline menu. Paste puts the copies at the history marker.pub(crate) fn clipboard_buttons(app: &mut SolveApp, ui: &mut egui::Ui, id: u64) {if crate::context_menu::button(ui, crate::i18n::tr_label("Copy"), "copy").clicked() {- let features = copy_targets(app, id);+ let features = menu_targets(app, id);let _ = app.run("timeline.copy", json!({ "features": features }));ui.close();}@@ -256,8 +294,32 @@ pub(crate) fn message_button(app: &SolveApp, ui: &mut egui::Ui, id: u64) {}}+/// Shift+click on a feature: select the features from the anchor (the last feature clicked, or+/// the last selected one) to this one. `order` is the timeline as drawn this frame, taken before+/// drawing so the range never mixes two orders. Ctrl as well adds the range to the selection.+fn select_range(app: &mut SolveApp, order: &[u64], id: u64, add: bool) {+ let anchor = app.tree.timeline_anchor.clone().or_else(|| selected_feature_ids(app).last().map(|f| anchor_key(*f)));+ let from = anchor.and_then(|key| order.iter().position(|f| anchor_key(*f) == key));+ let (Some(from), Some(to)) = (from, order.iter().position(|f| *f == id)) else {+ select_one(app, id);+ return;+ };+ let range = order.get(from.min(to)..=from.max(to)).unwrap_or_default();+ let items: Vec<_> = range.iter().map(|f| json!({"type": "feature", "id": f})).collect();+ let _ = app.run("select.set", json!({ "items": items, "add": add }));+}++/// A plain click on a feature: select it alone.+fn select_one(app: &mut SolveApp, id: u64) {+ app.tree.picked_joints.clear();+ app.tree.picked_timeline_groups.clear();+ app.tree.timeline_anchor = Some(anchor_key(id));+ let _ = app.run("select.set", json!({"items": [{"type": "feature", "id": id}]}));+}+/// Ctrl+click on a feature: add it to the selection, or take it out.fn toggle_feature(app: &mut SolveApp, id: u64) {+ app.tree.timeline_anchor = Some(anchor_key(id));let selected = selected_feature_ids(app);if selected.contains(&id) {let rest: Vec<_> =@@ -353,6 +415,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {.iter().map(|f| (f.id, f.name.clone(), icon_of(&f.kind), f.suppressed, f.kind.type_name(), TimelineKind::of(&f.kind))).collect();+ let order: Vec<u64> = feats.iter().map(|f| f.0).collect();// The feature whose body is under the cursor in the viewport.let st = app.session.world_state();let from_view = match &app.viewport.hover {@@ -416,12 +479,15 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {d.pick(&app.session, solidcraft_engine::Sel::Feature { id: *id });app.dialog = Some(d);}- } else if ui.input(|i| i.modifiers.command || i.modifiers.ctrl) {- toggle_feature(app, *id);} else {- app.tree.picked_joints.clear();- app.tree.picked_timeline_groups.clear();- let _ = app.run("select.set", json!({"items": [{"type": "feature", "id": id}]}));+ let modifiers = ui.input(|i| i.modifiers);+ if modifiers.shift {+ select_range(app, &order, *id, modifiers.command || modifiers.ctrl);+ } else if modifiers.command || modifiers.ctrl {+ toggle_feature(app, *id);+ } else {+ select_one(app, *id);+ }}}if resp.double_clicked() {@@ -459,10 +525,16 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {clipboard_buttons(app, ui, *id);message_button(app, ui, *id);ui.separator();- if crate::context_menu::button(ui, "Delete", "delete").clicked() {- delete_feature(app, *id);+ let targets = menu_targets(app, *id);+ let label = match targets.len() {+ 1 => crate::i18n::tr_label("Delete").to_string(),+ n => crate::i18n::format("timeline.delete_many", &[("count", &n.to_string())]),+ };+ if crate::context_menu::button(ui, &label, "delete").clicked() {+ delete_features(app, targets);ui.close();}+ delete_after_marker_button(app, ui, *id, i, marker);});x += 32.0;}@@ -759,6 +831,124 @@ mod tests {let first = h.app.session.doc.find_feature("First").map(|f| f.id).unwrap();assert_eq!(super::selected_feature_ids(&h.app), [first]);}+ fn three_boxes(left: bool) -> Harness {+ let mut h = two_boxes(left);+ h.app+ .run(+ "solid.box",+ json!({"length": 10, "width": 10, "height": 10, "corner": [40, 0, 0], "operation": "new_body", "name": "Third", "body_name": "Three"}),+ )+ .unwrap();+ h.app.run("select.clear", json!({})).unwrap();+ h.frames(4);+ h+ }++ fn names(h: &Harness) -> Vec<String> {+ h.app.session.doc.features.iter().map(|f| f.name.clone()).collect()+ }++ fn ids(h: &Harness, names: &[&str]) -> Vec<u64> {+ names.iter().map(|name| h.app.session.doc.find_feature(name).map(|f| f.id).unwrap()).collect()+ }++ /// Shift+click selects the range from the last feature clicked to this one, either way+ /// round; with nothing clicked yet it starts at the last selected feature (#5005).+ #[test]+ fn shift_click_selects_a_range_of_features() {+ let mut h = three_boxes(false);+ h.step(&json!({"click": {"handle": "timeline:Third"}})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:First"}, "shift": true})).unwrap();+ assert_eq!(super::selected_feature_ids(&h.app), ids(&h, &["First", "Second", "Third"]));+ h.step(&json!({"click": {"handle": "timeline:Second"}, "shift": true})).unwrap();+ assert_eq!(super::selected_feature_ids(&h.app), ids(&h, &["Second", "Third"]), "the range starts at the anchor, Third");++ h.app.tree.timeline_anchor = None;+ h.app.run("select.set", json!({"items": [{"type": "feature", "id": ids(&h, &["First"])[0]}]})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Second"}, "shift": true})).unwrap();+ assert_eq!(super::selected_feature_ids(&h.app), ids(&h, &["First", "Second"]));+ }++ /// Delete in the menu of a selected feature deletes the whole selection in one undo step,+ /// and says how many; on a feature outside the selection it deletes that one (#5005).+ #[test]+ fn the_feature_menu_deletes_the_selected_features() {+ let mut h = three_boxes(false);+ h.step(&json!({"click": {"handle": "timeline:Third"}, "button": "right"})).unwrap();+ assert!(h.widget("Delete").is_some());+ h.step(&json!({"key": "Escape"})).unwrap();++ h.step(&json!({"click": {"handle": "timeline:First"}})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Second"}, "ctrl": true})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Second"}, "button": "right"})).unwrap();+ h.step(&json!({"widget": "Delete 2 Selected Features"})).unwrap();+ h.settle();+ assert!(h.app.dialog.is_none(), "nothing else depends on them");+ assert_eq!(names(&h), ["Third"]);+ h.app.run("edit.undo", json!({})).unwrap();+ assert_eq!(names(&h), ["First", "Second", "Third"]);+ }++ /// The menu of a feature after the history marker deletes every feature after the marker,+ /// and says how many; features before the marker, and a selection of several, don't offer+ /// it. In both timelines (#5005).+ #[test]+ fn a_feature_after_the_marker_deletes_everything_after_the_marker() {+ for left in [false, true] {+ let mut h = three_boxes(left);+ h.app.run("timeline.roll_to", json!({"position": 1})).unwrap();+ h.settle();+ h.step(&json!({"click": {"handle": "timeline:First"}, "button": "right"})).unwrap();+ assert!(h.widget("Delete 2 Features After History Marker").is_none(), "left: {left}");+ h.step(&json!({"key": "Escape"})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Second"}})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Third"}, "ctrl": true})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Third"}, "button": "right"})).unwrap();+ // (The history beside the browser has its own Delete Selected Features….)+ assert!(left || h.widget("Delete 2 Selected Features").is_some());+ assert!(h.widget("Delete 2 Features After History Marker").is_none(), "left: {left}");+ h.step(&json!({"key": "Escape"})).unwrap();+ h.app.run("select.clear", json!({})).unwrap();+ h.frames(2);++ h.step(&json!({"click": {"handle": "timeline:Third"}, "button": "right"})).unwrap();+ h.step(&json!({"widget": "Delete 2 Features After History Marker"})).unwrap();+ h.settle();+ assert_eq!(names(&h), ["First"], "left: {left}");+ h.app.run("edit.undo", json!({})).unwrap();+ assert_eq!(names(&h), ["First", "Second", "Third"], "left: {left}");+ }+ }++ /// Deleting a sketch together with the extrude that uses it asks nothing: the extrude is+ /// one of the features deleted, not one that goes with it or fails. The Delete key, with+ /// the features picked in the timeline, does the same (#5005).+ #[test]+ fn deleting_a_feature_with_its_dependents_does_not_ask() {+ let mut h = Harness::new();+ h.app.run("sketch.create", json!({"plane": "XY", "name": "Base"})).unwrap();+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [10, 10]})).unwrap();+ h.app.run("sketch.finish", json!({})).unwrap();+ h.app.run("solid.extrude", json!({"sketch": "Base", "distance": 10, "operation": "new", "name": "Depth"})).unwrap();+ h.app.run("select.clear", json!({})).unwrap();+ h.frames(4);+ h.step(&json!({"click": {"handle": "timeline:Base"}})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Depth"}, "shift": true})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Depth"}, "button": "right"})).unwrap();+ h.step(&json!({"widget": "Delete 2 Selected Features"})).unwrap();+ h.settle();+ assert!(h.app.dialog.is_none());+ assert!(names(&h).is_empty());++ h.app.run("edit.undo", json!({})).unwrap();+ h.frames(4);+ h.step(&json!({"click": {"handle": "timeline:Base"}})).unwrap();+ h.step(&json!({"click": {"handle": "timeline:Depth"}, "shift": true})).unwrap();+ h.step(&json!({"key": "Delete"})).unwrap();+ h.settle();+ assert!(names(&h).is_empty());+ }+#[test]fn both_strips_keep_selection_reorder_marker_and_transport() {use crate::scenario::{handle_at, rect_of};diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex 3c5cd080d1..6886d2d856 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -5,7 +5,9 @@ use egui::{Rect, Sense, Stroke, pos2, vec2};use serde_json::json;use crate::theme::Tokens;-use crate::timeline::{TimelineKind, clipboard_buttons, delete_feature, delete_features, icon_of, message_button, selected_feature_ids};+use crate::timeline::{+ TimelineKind, clipboard_buttons, delete_after_marker_button, delete_feature, delete_features, icon_of, message_button, selected_feature_ids,+};use crate::{SolveApp, icons};const FOLDER_INDENT: f32 = 14.0;@@ -51,7 +53,7 @@ impl TimelineItem {fn key(self) -> String {match self {TimelineItem::Group(id) => format!("g:{id}"),- TimelineItem::Feature(id) => format!("f:{id}"),+ TimelineItem::Feature(id) => crate::timeline::anchor_key(id),}}}@@ -1088,6 +1090,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) {delete_feature(app, *id);ui.close();}+ delete_after_marker_button(app, ui, *id, index, marker);});if names && has_patterns && patterns_open {let depth = group_id.map_or(1, |group| group_depth(&groups, group) + 2);