Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Background save edited meanwhile: undoing back to the saved state is unmodified (#1721)

bflatastic8a7e36ede870
diff --git a/crates/engine/src/cmd/fileio/save.rs b/crates/engine/src/cmd/fileio/save.rs
index 99f29e27e..fdc8584c7 100644
--- a/crates/engine/src/cmd/fileio/save.rs
+++ b/crates/engine/src/cmd/fileio/save.rs
@@ -609,8 +609,11 @@ impl SaveJob {
if Arc::ptr_eq(&st.doc, &self.source) {
st.doc = self.snapshot.clone();
} else {
- // Edited while the save ran: the dates still go on, the edits stay unsaved.
+ // Edited while the save ran: the dates still go on, the edits stay unsaved. The
+ // undo history holds the document as it was before the dates, so that is the
+ // saved state: undoing back to it leaves the document unmodified.
stamp_save_dates(st, at);
+ return st.mark_saved_as(&self.source);
}
}
st.mark_saved_as(&self.snapshot);
diff --git a/crates/engine/src/cmd/fileio/tests.rs b/crates/engine/src/cmd/fileio/tests.rs
index 540ef77c4..c3b49ca23 100644
--- a/crates/engine/src/cmd/fileio/tests.rs
+++ b/crates/engine/src/cmd/fileio/tests.rs
@@ -523,4 +523,7 @@ fn a_failed_save_does_not_stamp_the_documents_dates() {
assert_eq!(st.doc.metadata.modified, Some(777));
assert_eq!(st.path.as_deref(), Some("/x/z.vectorcraft"));
assert!(st.is_dirty());
+ // Undoing the edit is back at what the file holds.
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert!(!s.doc().unwrap().is_dirty());
}
diff --git a/crates/ui-egui/src/tests_background.rs b/crates/ui-egui/src/tests_background.rs
index c0b92a491..bd10987e6 100644
--- a/crates/ui-egui/src/tests_background.rs
+++ b/crates/ui-egui/src/tests_background.rs
@@ -70,8 +70,9 @@ fn a_50k_path_save_returns_at_once_and_the_file_appears_later() {
assert!(written(&files).is_empty(), "nothing written yet");
assert_eq!(app.background.jobs.len(), 1);
assert!(app.ui.status.starts_with("Saving big.vectorcraft"));
- // The document is saved once the file is written.
- assert!(app.session.doc().unwrap().is_dirty() && app.session.doc().unwrap().path.is_none());
+ // The file is the document's once it is written (and its dates are stamped then, #1721: until
+ // then this document, never edited, is as it was).
+ assert!(!app.session.doc().unwrap().is_dirty() && app.session.doc().unwrap().path.is_none());
gate.open();
background::wait_all(&mut app);
assert_eq!(written(&files), ["/docs/big.vectorcraft"]);