diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 6807d1cce..242c86b97 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -415,7 +415,11 @@ impl Session { // touched wait, also when another command runs them (a script, or a recording that stops // and saves). Only the run's own steps go ahead. Other workbooks stay editable. let locked = self.active().is_some_and(|d| self.macro_debug.as_ref().is_some_and(|m| m.locks(d.uid) && !m.stepping())); - if spec.undoable && id != "macro.debug" && locked { + // Stopping Record Actions saves a script into the workbook; refuse it before it takes the + // recording, so stopping again after the run keeps what was recorded. + let stops_record_actions = + id == "automate.recordActions" && (params.get("stop").and_then(Json::as_bool) == Some(true) || self.recording.is_some()); + if (spec.undoable || stops_record_actions) && id != "macro.debug" && locked { return Err(EngineError::Disabled(id.to_string(), macros::debug::BUSY.into())); } let before = self.active().map(|d| (d.uid, d.wb.clone(), d.selection.clone())); diff --git a/crates/engine/src/macros/debug.rs b/crates/engine/src/macros/debug.rs index b1e53cf9b..8c5b7e201 100644 --- a/crates/engine/src/macros/debug.rs +++ b/crates/engine/src/macros/debug.rs @@ -468,5 +468,10 @@ mod tests { let r = s.execute("macro.debug", json!({"action": "step"})).unwrap(); assert_eq!(r["executed"], 2, "{r}"); assert!(s.macro_debug.is_none()); + // The recording was kept: stopping now saves it. + let saved = s.execute("automate.recordActions", json!({"stop": true, "name": "S"})).unwrap(); + assert_eq!(saved["saved"], "S", "{saved}"); + let scripts = s.execute("automate.allScripts", json!({})).unwrap(); + assert_eq!(scripts[0]["name"], "S", "{scripts}"); } }