SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
History: Delete on a selected feature deletes the selection in both timelines (#8861) (#8867)
Daniel32c8b231992c
diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex 07e040474c..4349eded8a 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -257,11 +257,6 @@ fn slot_at(xs: &[f32], end: f32, x: f32) -> usize {best.0}-/// Ask before deleting a feature others depend on; delete right away otherwise.-pub(crate) fn delete_feature(app: &mut SolveApp, id: u64) {- delete_features(app, vec![id]);-}-/// Check what deleting `ids` takes with it or makes fail (off the window thread when that takes a/// while, #2678), then delete them or ask first.pub(crate) fn delete_features(app: &mut SolveApp, ids: Vec<u64>) {@@ -329,6 +324,20 @@ pub(crate) fn menu_targets(app: &SolveApp, id: u64) -> Vec<u64> {if selected.contains(&id) { selected } else { vec![id] }}+/// Delete in a feature's menu, in both timelines: the selected features when the right-clicked+/// one is among them, labelled with how many, else that feature alone (#5005).+pub(crate) fn delete_button(app: &mut SolveApp, ui: &mut egui::Ui, id: u64) {+ 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();+ }+}+/// 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()@@ -992,15 +1001,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {clipboard_buttons(app, ui, *id);message_button(app, ui, *id);ui.separator();- 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_button(app, ui, *id);delete_after_marker_button(app, ui, *id, i, marker);});x += 32.0;@@ -1889,23 +1890,28 @@ mod tests {}/// 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).+ /// and says how many; on a feature outside the selection it deletes that one (#5005). The+ /// same in both timelines, and the history beside the browser no longer adds its own Delete+ /// Selected Features… to a feature's menu (#8861).#[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();+ for left in [false, true] {+ let mut h = three_boxes(left);+ h.step(&json!({"click": {"handle": "timeline:Third"}, "button": "right"})).unwrap();+ assert!(h.widget("Delete").is_some(), "left: {left}");+ 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"]);+ 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();+ assert!(h.widget("Delete Selected Features…").is_none(), "left: {left}");+ 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"], "left: {left}");+ h.app.run("edit.undo", json!({})).unwrap();+ assert_eq!(names(&h), ["First", "Second", "Third"], "left: {left}");+ }}/// The menu of a feature after the history marker deletes every feature after the marker,@@ -1923,8 +1929,7 @@ mod tests {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 Selected Features").is_some(), "left: {left}");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();diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex 3ef74922ce..f393d2c2f8 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -7,7 +7,7 @@ use serde_json::json;use crate::history_rows::{HistoryFeature, HistoryRows};use crate::theme::Tokens;use crate::timeline::{- TimelineKind, clipboard_buttons, delete_after_marker_button, delete_feature, delete_features, icon_of, message_button, selected_feature_ids,+ TimelineKind, clipboard_buttons, delete_after_marker_button, delete_button, delete_features, icon_of, message_button, selected_feature_ids,};use crate::{SolveApp, icons};@@ -671,7 +671,7 @@ fn select_item(app: &mut SolveApp, ui: &egui::Ui, item: TimelineItem, order: &[T}}-fn selection_actions(app: &mut SolveApp, ui: &mut egui::Ui, groups: &[solidcraft_engine::doc::TimelineGroup]) {+fn selection_actions(app: &mut SolveApp, ui: &mut egui::Ui, groups: &[solidcraft_engine::doc::TimelineGroup], feature_menu: bool) {let features = selected_feature_ids(app);let selected_groups = app.tree.picked_timeline_groups.clone();let has_selection = !features.is_empty() || !selected_groups.is_empty();@@ -737,7 +737,9 @@ fn selection_actions(app: &mut SolveApp, ui: &mut egui::Ui, groups: &[solidcraftui.close();}}- if !features.is_empty() {+ // A feature's menu has its own Delete, which deletes the selection ([`delete_button`]): a+ // right-click on a feature outside the selection selects that feature first.+ if !features.is_empty() && !feature_menu {ui.separator();if crate::context_menu::button(ui, "Delete Selected Features…", "delete").clicked() {delete_features(app, features);@@ -1125,7 +1127,7 @@ fn vertical_group_row(ui.close();}ui.separator();- selection_actions(app, ui, groups);+ selection_actions(app, ui, groups, false);});open}@@ -1570,12 +1572,9 @@ fn feature_row(app: &mut SolveApp, ui: &mut egui::Ui, rows: &mut Rows, index: usclipboard_buttons(app, ui, id);message_button(app, ui, id);ui.separator();- selection_actions(app, ui, groups);+ selection_actions(app, ui, groups, true);ui.separator();- if crate::context_menu::button(ui, "Delete", "delete").clicked() {- delete_feature(app, id);- ui.close();- }+ delete_button(app, ui, id);delete_after_marker_button(app, ui, id, index, marker);});if edit {