Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Feature editor: Undo, Redo and the History bar wait while an editor is open (#10688) (#10786)

Joberndo2ae13ba9cffe
diff --git a/assets/locales/pending/history-waits-for-editor.json b/assets/locales/pending/history-waits-for-editor.json
new file mode 100644
index 0000000000..dec7ac03a8
--- /dev/null
+++ b/assets/locales/pending/history-waits-for-editor.json
@@ -0,0 +1,9 @@
+{
+ "ar": { "ui.history_waits_for_editor": "ينتظر التراجع والإعادة والسجل حتى يكتمل فتح محرر الميزة" },
+ "de": { "ui.history_waits_for_editor": "Rückgängig, Wiederholen und Verlauf warten, bis der Feature-Editor geöffnet ist" },
+ "en": { "ui.history_waits_for_editor": "Undo, Redo and History wait until the feature editor has opened" },
+ "he": { "ui.history_waits_for_editor": "ביטול, ביצוע מחדש וציר הזמן ממתינים עד שעורך הפעולה ייפתח" },
+ "ja": { "ui.history_waits_for_editor": "元に戻す、やり直す、履歴は、フィーチャーエディターが開くまで待機します" },
+ "vi": { "ui.history_waits_for_editor": "Hoàn tác, Làm lại và Lịch sử sẽ chờ cho đến khi trình chỉnh sửa tính năng mở xong" },
+ "zh": { "ui.history_waits_for_editor": "撤销、重做和历史将等待特征编辑器打开" }
+}
diff --git a/crates/ui-egui/src/deferred.rs b/crates/ui-egui/src/deferred.rs
index 30991ac8b0..8f451575f4 100644
--- a/crates/ui-egui/src/deferred.rs
+++ b/crates/ui-egui/src/deferred.rs
@@ -140,6 +140,9 @@ impl SolveApp {
if id == "timeline.play" {
return self.run(id, params);
}
+ if matches!(id, "edit.undo" | "edit.redo" | "timeline.roll_to") {
+ self.close_editor_for_history()?;
+ }
// A manual history action takes over from playback. Playback takes its state out
// while submitting its own next step, then puts it back to wait for that step.
crate::timeline::stop_playback(self);
diff --git a/crates/ui-egui/src/extrude_edit_tests.rs b/crates/ui-egui/src/extrude_edit_tests.rs
index b2a4c4bfbd..1caecbd2b0 100644
--- a/crates/ui-egui/src/extrude_edit_tests.rs
+++ b/crates/ui-egui/src/extrude_edit_tests.rs
@@ -55,19 +55,49 @@ fn undoing_the_edited_feature_closes_its_editor_and_preserves_redo() {
assert!(h.app.dialog.is_none(), "the restored feature can be edited normally");
}
+// An editor kept open over an Undo refused its OK and Cancel afterwards, and Redo then lost the
+// edited feature's place (#10688): the Undo cancels it first, as starting another tool does.
#[test]
-fn undo_that_keeps_the_edited_feature_keeps_its_editor() {
+fn undo_that_keeps_the_edited_feature_cancels_its_editor_first() {
let mut h = make(json!({}));
let feature = h.app.session.doc.find_feature("Depth").unwrap().id;
h.app.run("solid.box", json!({"corner":[30,0,0],"length":2,"width":2,"height":2})).unwrap();
+ let full = h.app.session.doc.clone();
open(&mut h);
h.app.start("edit.undo");
h.frames(8);
assert!(h.app.session.doc.feature(feature).is_some());
- assert_eq!(h.app.dialog.as_ref().unwrap().editing.map(|(id, _)| id), Some(feature));
- assert!(h.app.editing_state.is_some());
- assert!(h.app.session.feature_edit_sketch.is_some());
+ assert!(h.app.dialog.is_none() && h.app.editing_state.is_none());
+ assert!(h.app.session.feature_edit_sketch.is_none());
+ assert_eq!(h.app.session.doc.features.len(), 2);
+ assert_eq!(h.app.session.doc.marker, None, "the editor's rollback is put back before the Undo");
assert_eq!(h.app.session.redo.len(), 1);
+
+ h.app.start("edit.redo");
+ h.frames(8);
+ assert_eq!(*h.app.session.doc, *full, "Undo then Redo leaves the design as it was");
+ open(&mut h);
+ h.step(&json!({"widget":"OK"})).unwrap();
+ assert!(h.app.dialog.is_none(), "the feature can be edited again");
+ assert!(h.app.status.as_ref().is_none_or(|s| !s.0.contains("changed while the feature editor was open")), "{:?}", h.app.status);
+}
+
+// A History step while an editor is open moved from the editor's rollback and left OK and
+// Cancel refusing the design (#10688): the step cancels the editor, then moves from the marker.
+#[test]
+fn a_history_step_cancels_the_editor_and_steps_from_the_design_marker() {
+ let mut h = make(json!({}));
+ h.app.run("solid.box", json!({"corner":[30,0,0],"length":2,"width":2,"height":2})).unwrap();
+ open(&mut h);
+ assert_eq!(h.app.session.doc.marker, Some(1), "Edit Feature rolls back to the extrude");
+ crate::timeline::run_transport(&mut h.app, crate::ui_kit::HistoryTransport::Back);
+ h.frames(8);
+ assert!(h.app.dialog.is_none() && h.app.editing_state.is_none());
+ assert_eq!(h.app.session.doc.marker, Some(2), "one step back from the end, not from the editor's rollback");
+ crate::timeline::run_transport(&mut h.app, crate::ui_kit::HistoryTransport::Last);
+ h.frames(8);
+ assert_eq!(h.app.session.doc.marker, None);
+ assert_eq!(h.app.session.world_state().body("Main").unwrap().mesh().bounds().max.z, 10.0);
}
#[test]
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 8b8b5e5816..b83301bfef 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1158,6 +1158,10 @@ impl SolveApp {
if self.file_load.busy() || self.file_picker.is_some() || self.saving.is_some() {
return Err("a file operation is in progress".into());
}
+ // The editor's own marker moves come through here, so only Undo, Redo and Play close it.
+ if matches!(id, "edit.undo" | "edit.redo" | "timeline.play") {
+ self.close_editor_for_history()?;
+ }
// Commands may start only detected slicers and the programs the user added under Custom….
if matches!(id, "file.save_mesh" | "file.send_to_slicer") {
solidcraft_engine::slicers::set_chosen_programs(&self.preferences.custom_slicers);
@@ -2092,6 +2096,22 @@ impl SolveApp {
self.open_feature_edit(id, marker, original);
}
+ /// Undo, Redo and the History bar would change the design under an open feature editor (Edit
+ /// Hole, Edit Box, …), whose OK and Cancel then refuse it (#10688). They cancel the editor
+ /// first, putting its marker back, as starting another tool does; while it is still opening
+ /// they wait for it.
+ pub(crate) fn close_editor_for_history(&mut self) -> Result<(), String> {
+ if self.pending_feature_edit.is_some() {
+ let why = i18n::tr("ui.history_waits_for_editor").to_string();
+ self.set_status(why.clone(), true);
+ return Err(why);
+ }
+ if self.editing_state.is_some() || self.dialog.as_ref().is_some_and(|d| d.editing.is_some()) {
+ dialogs::cancel(self);
+ }
+ Ok(())
+ }
+
fn open_feature_edit(&mut self, id: u64, marker: Option<usize>, original: Session) {
self.editing_state = Some(dialogs::EditingState { source: self.session.scratch(), original });
// The id check matters while another feature's reopening is still pending: a later call
diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rs
index 7ee3cfd7d3..8a113f1f58 100644
--- a/crates/ui-egui/src/timeline.rs
+++ b/crates/ui-egui/src/timeline.rs
@@ -16,6 +16,10 @@ use crate::theme::Tokens;
/// Apply transport actions from the current marker; endpoints stay bounded, including an
/// empty design. All orientations reach the same rollback command.
pub(crate) fn run_transport(app: &mut SolveApp, control: crate::ui_kit::HistoryTransport) {
+ // A step moves from the marker the design has, not the one an open editor rolled to (#10688).
+ if app.close_editor_for_history().is_err() {
+ return;
+ }
let n = app.session.doc.features.len();
let marker = app.session.doc.marker.unwrap_or(n);
let position = match control {