Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/app/automation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,21 @@ impl OpenCADStudio {
/// Handle one JSON request line and return the JSON response.
#[cfg(any(test, not(target_arch = "wasm32")))]
pub(crate) fn automation_op(&mut self, line: &str) -> Value {
// A test build checks that a change of the drawing has an undo step.
#[cfg(all(test, not(target_arch = "wasm32")))]
let undo_guard = super::update::undo_record_guard::begin_request(
self,
"automation",
&serde_json::from_str::<Value>(line).unwrap_or(Value::Null),
);
let response = self.automation_op_unguarded(line);
#[cfg(all(test, not(target_arch = "wasm32")))]
super::update::undo_record_guard::end(self, undo_guard);
response
}

#[cfg(any(test, not(target_arch = "wasm32")))]
fn automation_op_unguarded(&mut self, line: &str) -> Value {
// The plugin pump exists only on native targets (the plugins are
// native processes); on wasm this is a no-op.
#[cfg(not(target_arch = "wasm32"))]
Expand Down
11 changes: 11 additions & 0 deletions src/app/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,17 @@
}

pub(super) fn control_request(&mut self, req: Value) -> (Value, Task<Message>) {
// A test build checks that a change of the drawing has an undo step.
#[cfg(all(test, not(target_arch = "wasm32")))]
let undo_guard =
crate::app::update::undo_record_guard::begin_request(self, "control", &req);
let response = self.control_request_unguarded(req);
#[cfg(all(test, not(target_arch = "wasm32")))]
crate::app::update::undo_record_guard::end(self, undo_guard);
response
}

fn control_request_unguarded(&mut self, req: Value) -> (Value, Task<Message>) {

Check warning on line 713 in src/app/control/mod.rs

View workflow job for this annotation

GitHub Actions / health (informational)

Long function

control_request_unguarded is 572 lines (guide: 150)
// First control contact marks the session automated (#1349): a
// DonationPrompt that is still queued (not yet shown) is dropped so
// automation never waits behind it, and `queue_startup_prompts`
Expand Down
42 changes: 42 additions & 0 deletions src/app/undo_sweep_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,39 @@ fn palette_cases(d: &Drawing) -> Vec<Case> {
]
}

/// Changes of the current layer, colour, lineweight and linetype: nothing is
/// selected, and the Properties palette or the ribbon sends its message.
fn current_value_cases() -> Vec<Case> {
use document::types::{Color, LineWeight};
let case = |name: &str, message: Message| Case {
name: format!("Nothing selected: {name}"),
steps: vec![
Step::Op(serde_json::json!({"op": "select", "clear": true, "handles": []})),
Step::Send(Box::new(message)),
],
};
let (layer, linetype) = ("Walls".to_string(), "Continuous".to_string());
vec![
case("palette layer", Message::PropLayerChanged(layer.clone())),
case("palette color", Message::PropColorChanged(Color::Index(1))),
case(
"palette lineweight",
Message::PropLwChanged(LineWeight::W0_50),
),
case(
"palette linetype",
Message::PropLinetypeChanged(linetype.clone()),
),
case("ribbon layer", Message::RibbonLayerChanged(layer)),
case("ribbon color", Message::RibbonColorChanged(Color::Index(1))),
case(
"ribbon lineweight",
Message::RibbonLineweightChanged(LineWeight::W0_50),
),
case("ribbon linetype", Message::RibbonLinetypeChanged(linetype)),
]
}

/// Text made in an editor: the command stops with the editor open, the text
/// goes in, and the editor's OK commits it.
fn editor_cases() -> Vec<Case> {
Expand Down Expand Up @@ -544,6 +577,15 @@ fn every_palette_change_is_undone_and_redone_exactly() {
}

/// The same for text that an editor makes.
#[test]
fn every_change_of_a_current_value_is_undone_and_redone_exactly() {
let failures: Vec<String> = current_value_cases()
.iter()
.flat_map(|case| check_steps(&case.name, &case.steps))
.collect();
assert!(failures.is_empty(), "{}", failures.join("\n"));
}

#[test]
fn every_editor_commit_is_undone_and_redone_exactly() {
let failures: Vec<String> = editor_cases()
Expand Down
4 changes: 4 additions & 0 deletions src/app/update/command/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl OpenCADStudio {
if self.has_property_selection(i) {
return Task::none();
}
self.push_undo_snapshot(i, "CLAYER");
// No selection — change the creation default. Persist
// into the tab's header (CLAYER) so it survives a tab
// switch and rides the next save. #21.
Expand Down Expand Up @@ -52,6 +53,7 @@ impl OpenCADStudio {
if self.has_property_selection(i) {
return Task::none();
}
self.push_undo_snapshot(i, "CECOLOR");
// Persist the new default into the tab's header so it
// round-trips through tab switches and writes back on
// save (CECOLOR). #21.
Expand Down Expand Up @@ -80,6 +82,7 @@ impl OpenCADStudio {
if self.has_property_selection(i) {
return Task::none();
}
self.push_undo_snapshot(i, "CELWEIGHT");
// Persist into the tab's header (CELWEIGHT). #21.
self.tabs[i].scene.document.header.current_line_weight = lw.value();
self.tabs[i].dirty = true;
Expand All @@ -106,6 +109,7 @@ impl OpenCADStudio {
if self.has_property_selection(i) {
return Task::none();
}
self.push_undo_snapshot(i, "CELTYPE");
// Persist into the tab's header (CELTYPE). Resolve to a
// handle when the name matches a line_types entry so the
// handle-based lookup stays in sync. #21.
Expand Down
9 changes: 2 additions & 7 deletions src/app/update/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9129,14 +9129,9 @@ impl OpenCADStudio {
let i = self.active_tab;
let handles = self.property_target_handles(i);
if handles.is_empty() {
if self.has_property_selection(i) {
return Task::none();
}
self.tabs[i].scene.document.header.current_line_weight = lw.value();
self.tabs[i].dirty = true;
self.ribbon.active_lineweight = lw;
let task = self.on_ribbon_lineweight_changed(lw);
self.refresh_properties();
return Task::none();
return task;
}
self.apply_property_op(i, "CHPROP", &handles, |app, handle| {
if let Some(entity) = app.tabs[i].scene.document.get_entity_mut(handle) {
Expand Down
8 changes: 8 additions & 0 deletions src/app/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ mod qselect;
mod style;
pub(in crate::app) mod table_style_cells;
pub(crate) mod style_import;
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(in crate::app) mod undo_record_guard;
#[cfg(all(test, not(target_arch = "wasm32")))]
mod undo_record_guard_tests;
pub(in crate::app) mod util;
mod viewport;
pub(in crate::app) mod viewport_snap;
Expand Down Expand Up @@ -1148,6 +1152,8 @@ impl OpenCADStudio {
// answered move writes it. Answer the withheld position first, so the
// order stays the order the pointer reported — the hazard
// `on_snap_dwell_tick` documents is a replay that lands *after*.
#[cfg(all(test, not(target_arch = "wasm32")))]
let undo_guard = undo_record_guard::begin_message(self, &msg);
let owed = self.flush_owed_pointer_move(&msg);
let task = Task::batch([owed, self.update_inner(msg)]);
let perf_dispatch_ms = crate::perf::elapsed_ms(perf_started);
Expand Down Expand Up @@ -1181,6 +1187,8 @@ impl OpenCADStudio {
// Close the document-level first-touch transaction started by
// push_undo_snapshot at this message boundary.
self.finish_all_pending_history();
#[cfg(all(test, not(target_arch = "wasm32")))]
undo_record_guard::end(self, undo_guard);
if self.tabs[self.active_tab].active_cmd.is_none() {
self.tool_palettes.placing = None;
}
Expand Down
Loading
Loading