Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/src/messages/portfolio/document/document_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ pub enum DocumentMessage {
StartTransaction,
EndTransaction,
CommitTransaction,
CancelTransaction,
AbortTransaction,
RepeatedAbortTransaction {
undo_count: usize,
Expand Down
20 changes: 15 additions & 5 deletions editor/src/messages/portfolio/document/document_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,16 +1286,20 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> 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;
Expand All @@ -1304,9 +1308,15 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> 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;
Expand Down
Loading