* claim: #6003 * Save: a design changed while it is written stays unsaved, and scripts wait for it (#6003) Two of the gaps @raykholo found in #6003 were still open on main: - `engine.script` ran while the window's Save was being written: it calls the session directly, past `SolveApp::run`'s file-operation guard, and `drain_control` did not hold design-changing requests for a save. They now wait for the save like they wait for a file being loaded or picked. - `adopt_save` marked whatever the session held when the save finished as saved. It now takes up the state the save wrote (`done.saved`, and its visibility), so a change made meanwhile stays unsaved instead of being lost on close without a prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FN5eEMrqWWXqi65FcK8GXq --------- Co-authored-by: sascha2101 <221609842+sascha2101@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -470,9 +470,11 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Take up a save that ran on `done`, a [`Session::scratch`] copy of this session that
|
||||
/// `file.save` or `file.save_as` ran on (on another thread, so the window keeps drawing)
|
||||
/// while this one did not change: the name the save gave the design, its
|
||||
/// file, and its saved state, as running the command here would have left them.
|
||||
/// `file.save` or `file.save_as` ran on (on another thread, so the window keeps drawing):
|
||||
/// the name the save gave the design, its file, and its saved state, as running the command
|
||||
/// here would have left them. What is saved is the design the file holds, `done`'s, not this
|
||||
/// one's: a change made here while the save was written is not in the file, so it stays
|
||||
/// unsaved (#6003).
|
||||
pub fn adopt_save(&mut self, done: &Session) {
|
||||
if done.doc.name != self.doc.name {
|
||||
let (from, to) = (self.doc.name.clone(), done.doc.name.clone());
|
||||
@@ -481,7 +483,8 @@ impl Session {
|
||||
self.path.clone_from(&done.path);
|
||||
self.disk = done.disk;
|
||||
self.read_only = done.read_only;
|
||||
self.mark_saved();
|
||||
self.saved = done.saved.clone();
|
||||
self.saved_visibility = done.saved_visibility.clone();
|
||||
}
|
||||
|
||||
/// Another program or computer wrote the design's file since it was opened or last saved:
|
||||
@@ -923,6 +926,33 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #6003: a session changed while its save ran on a copy takes up the save's file and name,
|
||||
/// but only what the file holds counts as saved: the change stays unsaved, and undoing it
|
||||
/// leaves nothing unsaved again. A hidden body is a change too.
|
||||
#[test]
|
||||
fn a_change_made_while_a_copy_saves_stays_unsaved() {
|
||||
let dir = std::env::temp_dir().join(format!("solidcraft-adopt-changed-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("Bracket.solidcraft");
|
||||
for hide in [false, true] {
|
||||
let mut s = Session::default();
|
||||
s.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10, "body_name": "Block"})).unwrap();
|
||||
let mut copy = s.scratch();
|
||||
copy.execute("file.save_as", &json!({"path": path.to_string_lossy()})).unwrap();
|
||||
if hide {
|
||||
s.execute("browser.visibility", &json!({"items": ["Block"], "visible": false})).unwrap();
|
||||
} else {
|
||||
s.execute("solid.sphere", &json!({"diameter": 4})).unwrap();
|
||||
}
|
||||
s.adopt_save(©);
|
||||
assert_eq!((s.path.as_deref(), s.doc.name.as_str()), (path.to_str(), "Bracket"));
|
||||
assert!(s.is_dirty(), "hide {hide}: the change is not in the file");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(!s.is_dirty(), "hide {hide}: back to what the file holds");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #5467: a script, the CLI or the control channel never gets a prompt. A Save over a file
|
||||
/// another program or computer changed since it was opened is refused with an error naming
|
||||
/// `overwrite`, which replaces it; a design opened read-only only saves to another file.
|
||||
|
||||
Reference in New Issue
Block a user