From d194bc6935068f2e065eafc60d0a65704c6e0213 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 1 Sep 2025 10:39:17 -0700 Subject: [PATCH] Add cancel transaction --- .../portfolio/document/document_message.rs | 1 + .../document/document_message_handler.rs | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) 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 aec19541a2..e425288cc6 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -1285,16 +1285,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; @@ -1302,9 +1306,15 @@ impl MessageHandler> for DocumentMes self.network_interface.finish_transaction(); self.document_redo_history.clear(); } - 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;