From d96f7a6dc4e9b0f3eec006540ad676f919287e88 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Tue, 1 Dec 2026 21:01:05 +0100 Subject: [PATCH] Keep host copy saves from marking the open document saved (cherry picked from commit 2624b9b9d2c2eafaa5c1ec07db8ec3d026bb2799) --- apps/pdfcraft-web/src/main.rs | 4 ++-- crates/ui-egui/src/editing/save.rs | 3 ++- crates/ui-egui/src/editing/tests.rs | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/pdfcraft-web/src/main.rs b/apps/pdfcraft-web/src/main.rs index 9991558f36..e7c26d9645 100644 --- a/apps/pdfcraft-web/src/main.rs +++ b/apps/pdfcraft-web/src/main.rs @@ -179,8 +179,8 @@ fn app_canvas() -> Option { /// says `file: false` and a host sends `bytes`. /// - `pdfcraft:open` (from the host): `{ name, bytes }` holding a PDF. It opens in a tab, like a /// `?file=` URL; a file over [`host::MAX_OPEN_BYTES`] is refused before it is copied. -/// - `pdfcraft:save` (to the host): `{ name, saveAs, bytes }` when the user saves, posted by the -/// browser file service. The host stores the file (and reports its own errors). +/// - `pdfcraft:save` (to the host): `{ name, saveAs, bytes }` when the user saves through the +/// connected bridge. The host stores the file and reports its own errors. /// - `pdfcraft:dirty` whenever unsaved work appears or goes away, `pdfcraft:failed` when the app /// couldn't start. #[cfg(target_arch = "wasm32")] diff --git a/crates/ui-egui/src/editing/save.rs b/crates/ui-egui/src/editing/save.rs index 04d49fd8ec..ccf5d4073a 100644 --- a/crates/ui-egui/src/editing/save.rs +++ b/crates/ui-egui/src/editing/save.rs @@ -266,8 +266,9 @@ impl PdfCraftApp { pub(super) fn save_to_host(&mut self, ctx: &egui::Context, id: DocId, name: &str, target: SaveTarget) -> Option { self.host_save.as_ref()?; let Some((_, bytes)) = self.document_bytes(ctx, id, target, None) else { return Some(false) }; - let result = self.host_save.as_ref()?(name, &bytes, target == SaveTarget::As); + let result = self.host_save.as_ref()?(name, &bytes, target != SaveTarget::InPlace); match result { + Ok(()) if target == SaveTarget::Copy => Some(true), Ok(()) => Some(self.finish_save(ctx, id, bytes, None)), Err(e) => { self.notify_fmt("Couldn't save {name}: {e}", &[("name", name), ("e", &e)]); diff --git a/crates/ui-egui/src/editing/tests.rs b/crates/ui-egui/src/editing/tests.rs index 9a3dcf8c5d..1a56997b74 100644 --- a/crates/ui-egui/src/editing/tests.rs +++ b/crates/ui-egui/src/editing/tests.rs @@ -98,9 +98,12 @@ fn host_save_delivers_pathless_document_and_preserves_failures() { assert!(!app.session.get(id).unwrap().dirty); assert!(app.session.get(id).unwrap().path.is_none(), "host delivery does not create a filesystem path"); assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::As), Some(true)); + app.apply_edit(&ctx, pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 }); + assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::Copy), Some(true)); + assert!(app.session.get(id).unwrap().dirty, "saving a copy does not mark the original saved"); let saved = received.lock().unwrap(); - assert_eq!(saved.len(), 2); - assert_eq!((&saved[0].0, saved[0].2, saved[1].2), (&"sample.pdf".to_string(), false, true)); + assert_eq!(saved.len(), 3); + assert_eq!((saved[0].0.as_str(), saved[0].2, saved[1].2, saved[2].2), ("sample.pdf", false, true, true)); let mut reopened = pdfcraft_engine::Session::new(); let opened = reopened.open("saved.pdf", None, saved[0].1.clone(), None).unwrap(); assert_eq!(reopened.get(opened).unwrap().info.pages[0].rotation, 90);