diff --git a/editor/src/messages/portfolio/document/document_message.rs b/editor/src/messages/portfolio/document/document_message.rs index 88c2159c6c..467f0f0eb7 100644 --- a/editor/src/messages/portfolio/document/document_message.rs +++ b/editor/src/messages/portfolio/document/document_message.rs @@ -183,6 +183,7 @@ pub enum DocumentMessage { StartTransaction, EndTransaction, CommitTransaction, + CancelTransaction, AbortTransaction, RepeatedAbortTransaction { undo_count: usize, diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 64cce7f12a..e42c15a17f 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -1286,16 +1286,20 @@ impl MessageHandler> for DocumentMes // Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents responses.add(PortfolioMessage::UpdateOpenDocumentsList); } - // Commits the transaction if the network was mutated since the transaction started, otherwise it aborts the transaction + // Commits the transaction if the network was mutated since the transaction started, otherwise it cancels the transaction DocumentMessage::EndTransaction => match self.network_interface.transaction_status() { TransactionStatus::Started => { - responses.add_front(DocumentMessage::AbortTransaction); + responses.add_front(DocumentMessage::CancelTransaction); } TransactionStatus::Modified => { responses.add_front(DocumentMessage::CommitTransaction); } TransactionStatus::Finished => {} }, + DocumentMessage::CancelTransaction => { + self.network_interface.finish_transaction(); + self.document_undo_history.pop_back(); + } DocumentMessage::CommitTransaction => { if self.network_interface.transaction_status() == TransactionStatus::Finished { return; @@ -1304,9 +1308,15 @@ impl MessageHandler> for DocumentMes self.document_redo_history.clear(); responses.add(PortfolioMessage::UpdateOpenDocumentsList); } - DocumentMessage::AbortTransaction => { - responses.add(DocumentMessage::RepeatedAbortTransaction { undo_count: 1 }); - } + DocumentMessage::AbortTransaction => match self.network_interface.transaction_status() { + TransactionStatus::Started => { + responses.add_front(DocumentMessage::CancelTransaction); + } + TransactionStatus::Modified => { + responses.add(DocumentMessage::RepeatedAbortTransaction { undo_count: 1 }); + } + TransactionStatus::Finished => {} + }, DocumentMessage::RepeatedAbortTransaction { undo_count } => { if self.network_interface.transaction_status() == TransactionStatus::Finished { return;