From 9fe0778a51d6520f76bd89ede32b56079690a2cb Mon Sep 17 00:00:00 2001 From: aniket giri Date: Fri, 2 Jan 2026 19:57:39 +0530 Subject: [PATCH] fix: move save state updates to SavedDocument handler Fixes #3558 - Cancelling document saving leads to content/modifications being lost Previously, set_save_state(true) was called in the SaveDocument handler before the save dialog even appeared. This caused the document to be marked as saved even if the user cancelled the save dialog. Now the save state updates (set_save_state, set_auto_save_state) are called in the SavedDocument handler, which only executes after the file has actually been written to disk. This ensures that: - Cancelling the save dialog keeps the document marked as unsaved - The asterisk indicator remains visible until the file is truly saved - No content/modifications are lost if the save is cancelled --- .../portfolio/document/document_message_handler.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 6402f609fd..4f3e1a9700 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -1046,11 +1046,6 @@ impl MessageHandler> for DocumentMes self.path = None; } - self.set_save_state(true); - responses.add(PortfolioMessage::AutoSaveActiveDocument); - // Update the save status of the just saved document - responses.add(PortfolioMessage::UpdateOpenDocumentsList); - responses.add(FrontendMessage::TriggerSaveDocument { document_id, name: format!("{}.{}", self.name.clone(), FILE_EXTENSION), @@ -1061,7 +1056,12 @@ impl MessageHandler> for DocumentMes DocumentMessage::SavedDocument { path } => { self.path = path; + // Mark the document as saved now that the file has actually been written + self.set_save_state(true); + self.set_auto_save_state(true); responses.add(PortfolioMessage::AutoSaveActiveDocument); + // Update the save status of the just saved document + responses.add(PortfolioMessage::UpdateOpenDocumentsList); // Update the name to match the file stem let document_name_from_path = self.path.as_ref().and_then(|path| {