Allow grouping local transactions even if remote peer edits in between

This commit is contained in:
Antonio Scandurra 2022-07-23 09:27:21 +02:00
parent 79f960b69e
commit 0fc7308932
4 changed files with 6 additions and 20 deletions

View file

@ -450,7 +450,6 @@ pub fn serialize_transaction(transaction: &Transaction) -> proto::Transaction {
.map(serialize_local_timestamp)
.collect(),
start: serialize_version(&transaction.start),
end: serialize_version(&transaction.end),
}
}
@ -467,7 +466,6 @@ pub fn deserialize_transaction(transaction: proto::Transaction) -> Result<Transa
.map(deserialize_local_timestamp)
.collect(),
start: deserialize_version(transaction.start.into()),
end: deserialize_version(transaction.end),
})
}

View file

@ -534,7 +534,6 @@ message Transaction {
LocalTimestamp id = 1;
repeated LocalTimestamp edit_ids = 2;
repeated VectorClockEntry start = 3;
repeated VectorClockEntry end = 4;
}
message LocalTimestamp {

View file

@ -564,7 +564,9 @@ fn test_history() {
assert_eq!(buffer.text(), "12cde6");
// Redo stack gets cleared after performing an edit.
buffer.start_transaction_at(now);
buffer.edit([(0..0, "X")]);
buffer.end_transaction_at(now);
assert_eq!(buffer.text(), "X12cde6");
buffer.redo();
assert_eq!(buffer.text(), "X12cde6");

View file

@ -92,7 +92,6 @@ pub struct Transaction {
pub id: TransactionId,
pub edit_ids: Vec<clock::Local>,
pub start: clock::Global,
pub end: clock::Global,
}
#[derive(Clone, Copy, Debug, PartialEq)]
@ -105,15 +104,6 @@ impl HistoryEntry {
pub fn transaction_id(&self) -> TransactionId {
self.transaction.id
}
fn push_edit(&mut self, edit_operation: &EditOperation) {
self.transaction
.edit_ids
.push(edit_operation.timestamp.local());
self.transaction
.end
.observe(edit_operation.timestamp.local());
}
}
struct History {
@ -162,8 +152,7 @@ impl History {
self.undo_stack.push(HistoryEntry {
transaction: Transaction {
id,
start: start.clone(),
end: start,
start,
edit_ids: Default::default(),
},
first_edit_at: now,
@ -209,7 +198,6 @@ impl History {
while let Some(prev_entry) = entries.next_back() {
if !prev_entry.suppress_grouping
&& entry.first_edit_at - prev_entry.last_edit_at <= self.group_interval
&& entry.transaction.start == prev_entry.transaction.end
{
entry = prev_entry;
new_len -= 1;
@ -223,13 +211,12 @@ impl History {
if let Some(last_entry) = entries_to_keep.last_mut() {
for entry in &*entries_to_merge {
for edit_id in &entry.transaction.edit_ids {
last_entry.push_edit(self.operations[edit_id].as_edit().unwrap());
last_entry.transaction.edit_ids.push(*edit_id);
}
}
if let Some(entry) = entries_to_merge.last_mut() {
last_entry.last_edit_at = entry.last_edit_at;
last_entry.transaction.end = entry.transaction.end.clone();
}
}
@ -257,9 +244,9 @@ impl History {
fn push_undo(&mut self, op_id: clock::Local) {
assert_ne!(self.transaction_depth, 0);
if let Some(Operation::Edit(edit)) = self.operations.get(&op_id) {
if let Some(Operation::Edit(_)) = self.operations.get(&op_id) {
let last_transaction = self.undo_stack.last_mut().unwrap();
last_transaction.push_edit(&edit);
last_transaction.transaction.edit_ids.push(op_id);
}
}