Skip to content

Commit 9fe0778

Browse files
committed
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
1 parent 2fa958a commit 9fe0778

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
10461046
self.path = None;
10471047
}
10481048

1049-
self.set_save_state(true);
1050-
responses.add(PortfolioMessage::AutoSaveActiveDocument);
1051-
// Update the save status of the just saved document
1052-
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
1053-
10541049
responses.add(FrontendMessage::TriggerSaveDocument {
10551050
document_id,
10561051
name: format!("{}.{}", self.name.clone(), FILE_EXTENSION),
@@ -1061,7 +1056,12 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
10611056
DocumentMessage::SavedDocument { path } => {
10621057
self.path = path;
10631058

1059+
// Mark the document as saved now that the file has actually been written
1060+
self.set_save_state(true);
1061+
self.set_auto_save_state(true);
10641062
responses.add(PortfolioMessage::AutoSaveActiveDocument);
1063+
// Update the save status of the just saved document
1064+
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
10651065

10661066
// Update the name to match the file stem
10671067
let document_name_from_path = self.path.as_ref().and_then(|path| {

0 commit comments

Comments
 (0)