diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 5b309f42c..d18833add 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -1330,7 +1330,7 @@ fn select_set(s: &mut Session, p: &Value) -> Result { s.selection.push(x); } } - s.revision += 1; + s.refresh_display(); Ok(json!({"selected": s.selection.len()})) } @@ -1387,7 +1387,7 @@ fn select_same_look(s: &mut Session, p: &Value) -> Result { fn select_clear(s: &mut Session, _p: &Value) -> Result { s.selection.clear(); - s.revision += 1; + s.refresh_display(); Ok(json!({"selected": 0})) } diff --git a/crates/engine/src/cmd/section.rs b/crates/engine/src/cmd/section.rs index ebae74fa2..15fb8d92a 100644 --- a/crates/engine/src/cmd/section.rs +++ b/crates/engine/src/cmd/section.rs @@ -24,7 +24,7 @@ fn section(s: &mut Session, p: &Value) -> Result { if bool_(p, "clear").unwrap_or(false) { s.section = None; s.status_slot(crate::status_items::StatusId::Section, false); - s.revision += 1; + s.refresh_display(); return serde_json::to_value(contract::SectionResult { section: None, param_warnings: Vec::new() }).map_err(|e| bad(cmd, e.to_string())); } // A named plane's world axis: which component of a point lies along its normal. @@ -82,7 +82,7 @@ fn section(s: &mut Session, p: &Value) -> Result { s.section_hatch = bool_(p, "hatch").unwrap_or(true); s.status_slot(crate::status_items::StatusId::Section, true); s.status_activated(crate::status_items::StatusId::Section); - s.revision += 1; + s.refresh_display(); let section = contract::Section { origin: [origin.x, origin.y, origin.z], normal: [normal.x, normal.y, normal.z], diff --git a/crates/engine/src/cmd/surface_analysis.rs b/crates/engine/src/cmd/surface_analysis.rs index cd1c051c7..aef24a62a 100644 --- a/crates/engine/src/cmd/surface_analysis.rs +++ b/crates/engine/src/cmd/surface_analysis.rs @@ -91,7 +91,7 @@ fn set(s: &mut Session, p: &Value, a: SurfaceAnalysis) -> Result { s.analysis = Some(a); } s.status_analysis_changed((!bool_(p, "clear").unwrap_or(false)).then_some(crate::status_items::StatusId::SurfaceAnalysis)); - s.revision += 1; + s.refresh_display(); let vector = |v: Vec3| [v.x, v.y, v.z]; let analysis = s.analysis.map(|a| match a { SurfaceAnalysis::Zebra { stripes } => contract::Analysis::Zebra { stripes }, @@ -155,7 +155,7 @@ fn continuity(s: &mut Session, p: &Value) -> Result { if bool_(p, "clear").unwrap_or(false) { s.continuity.clear(); s.status_analysis_changed(None); - s.revision += 1; + s.refresh_display(); return serde_json::to_value(contract::ContinuityResult::Cleared { analysis: "continuity".into(), cleared: true, @@ -273,7 +273,7 @@ fn continuity(s: &mut Session, p: &Value) -> Result { s.continuity = seams; } s.status_analysis_changed(Some(crate::status_items::StatusId::Continuity)); - s.revision += 1; + s.refresh_display(); serde_json::to_value(contract::ContinuityResult::Measured { analysis: "continuity".into(), samples, diff --git a/crates/engine/src/cmd/view_navigation.rs b/crates/engine/src/cmd/view_navigation.rs index 86e387a05..a068f6a7f 100644 --- a/crates/engine/src/cmd/view_navigation.rs +++ b/crates/engine/src/cmd/view_navigation.rs @@ -315,7 +315,7 @@ fn render_select(s: &mut Session, p: &Value) -> Result { let result = serde_json::to_value(request).map_err(|e| bad("view.render_select", e.to_string()))?; if !s.selection.is_empty() { s.selection.clear(); - s.revision += 1; + s.refresh_display(); } Ok(result) } diff --git a/crates/engine/src/computed_commands_tests.rs b/crates/engine/src/computed_commands_tests.rs index 5e6d6c0e1..5cfb70a15 100644 --- a/crates/engine/src/computed_commands_tests.rs +++ b/crates/engine/src/computed_commands_tests.rs @@ -149,6 +149,35 @@ fn editor_visibility_changes_allow_apply_and_preserve_separate_undo_steps() { } } +/// A section, an analysis or the selection changed while an editor is open changes only what is +/// shown: OK still applies the edit and Cancel puts the design back (#10687). +#[test] +fn editor_display_changes_allow_apply_and_cancel() { + let cases: [&[(&str, serde_json::Value)]; 5] = [ + &[("inspect.section", json!({"plane":"XZ","offset":1}))], + &[("inspect.section", json!({"plane":"XZ","offset":1})), ("inspect.section", json!({"clear":true}))], + &[("inspect.zebra", json!({"stripes":14.5}))], + &[("select.set", json!({"items":[{"type":"body","name":"Other"}]}))], + &[("select.clear", json!({}))], + ]; + for display in cases { + let (mut session, source, original, commands) = extrusion_editor(); + for (id, params) in display { + session.execute(id, params).unwrap(); + } + let prepared = + session.scratch().compute_editor_commands(&commands, &source, original).unwrap_or_else(|e| panic!("OK after {display:?}: {e}")); + session.accept_commands(prepared).unwrap(); + assert_editor_volume(&mut session, 12024.0); + let (mut session, source, original, _) = extrusion_editor(); + for (id, params) in display { + session.execute(id, params).unwrap(); + } + session.restore_editor(&source, original).unwrap_or_else(|e| panic!("Cancel after {display:?}: {e}")); + assert_editor_volume(&mut session, 6024.0); + } +} + #[test] fn editor_visibility_changes_allow_cancel_and_keep_undo_and_redo_at_the_original_marker() { for undo_hide in [false, true] { diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e99e06973..bb3a81c70 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -463,8 +463,9 @@ pub struct Session { pub log: Vec, /// Increments on every document change (views use it to refresh). pub revision: u64, - /// Revision increments caused only by visibility. Comparing both counters proves that - /// every intervening increment left an editor's document and model untouched. + /// Revision increments caused only by what is shown ([`Session::refresh_display`]). + /// Comparing both counters proves that every intervening increment left an editor's + /// document and model untouched. visibility_revision: u64, /// [`Document::browser_stamp`] when the browser's groups and order were last checked. browser_stamp: [u64; 6], @@ -1339,8 +1340,9 @@ impl Session { } } - /// Only what is hidden or shown changed: the model is untouched, so only the view revision - /// moves (the visibility caches are keyed on it) and the viewport redraws. + /// Only what is shown changed (hidden or shown items, a section or analysis, the selection): + /// the design and model are untouched, so only the view revision moves and the viewport + /// redraws. An open feature editor stays valid across it (#10687). pub(crate) fn refresh_display(&mut self) { self.revision += 1; self.visibility_revision += 1; diff --git a/crates/engine/src/status_items.rs b/crates/engine/src/status_items.rs index 5dff8791c..d6e333edb 100644 --- a/crates/engine/src/status_items.rs +++ b/crates/engine/src/status_items.rs @@ -144,7 +144,7 @@ impl Session { self.status_slot(id, active); } if self.status_items() != before { - self.revision += 1; + self.refresh_display(); } }