From ab236a6008a388e16a6c360ea76e16cfcae82d71 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 17 Aug 2022 11:26:05 +0200 Subject: [PATCH 1/2] Fix divergence bug in undo/redo As part of #1405, we changed the way we performed undo and redo to support combining transactions that were not temporally adjacent for IME purposes. We introduced a bug with that release that caused divergence when performing undo: the bug was caused by only changing the visibility of fragments whose insertion id was contained in the undo operation. However, an undo operation also affects deletions which we were mistakenly not considering. Randomized tests caught this but I guess we didn't run enough of them. --- crates/language/src/proto.rs | 2 -- crates/rpc/proto/zed.proto | 3 +-- crates/text/src/text.rs | 12 ++---------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rs index 047cef3ab6ad1fd738bed4c61774c38d74358064..df1e0e095997fd29da038883a8875ac6be07b3c7 100644 --- a/crates/language/src/proto.rs +++ b/crates/language/src/proto.rs @@ -39,7 +39,6 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation { local_timestamp: undo.id.value, lamport_timestamp: lamport_timestamp.value, version: serialize_version(&undo.version), - transaction_version: serialize_version(&undo.transaction_version), counts: undo .counts .iter() @@ -199,7 +198,6 @@ pub fn deserialize_operation(message: proto::Operation) -> Result { ) }) .collect(), - transaction_version: deserialize_version(undo.transaction_version), }, }), proto::operation::Variant::UpdateSelections(message) => { diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index f52815a8be60d306e5d328f4910cae30828c29a8..3da7f62ac7d837fbd2541508fb8c68cba93df128 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -901,8 +901,7 @@ message Operation { uint32 local_timestamp = 2; uint32 lamport_timestamp = 3; repeated VectorClockEntry version = 4; - repeated VectorClockEntry transaction_version = 6; - repeated UndoCount counts = 7; + repeated UndoCount counts = 5; } message UpdateSelections { diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index ff78f4a14b7418db61b1aca2066a9f19d125a596..1f2e4e7c7a95321a28e2a0e46885b90923869b87 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -512,7 +512,6 @@ pub struct EditOperation { pub struct UndoOperation { pub id: clock::Local, pub counts: HashMap, - pub transaction_version: clock::Global, pub version: clock::Global, } @@ -1109,14 +1108,8 @@ impl Buffer { let mut fragment = fragment.clone(); let fragment_was_visible = fragment.visible; - if fragment.was_visible(&undo.transaction_version, &self.undo_map) - || undo - .counts - .contains_key(&fragment.insertion_timestamp.local()) - { - fragment.visible = fragment.is_visible(&self.undo_map); - fragment.max_undos.observe(undo.id); - } + fragment.visible = fragment.is_visible(&self.undo_map); + fragment.max_undos.observe(undo.id); let old_start = old_fragments.start().1; let new_start = new_fragments.summary().text.visible; @@ -1297,7 +1290,6 @@ impl Buffer { id: self.local_clock.tick(), version: self.version(), counts, - transaction_version: transaction.start, }; self.apply_undo(&undo)?; let operation = Operation::Undo { From 9726d1f049161149ef67fb9354469a9139f38b5f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 17 Aug 2022 11:31:48 +0200 Subject: [PATCH 2/2] Bump protocol version --- crates/rpc/src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc/src/rpc.rs b/crates/rpc/src/rpc.rs index c4017015f9067280d76de94f6bcc242cdf6a1cca..b3c7aa0046057fb390cdd34d75ef413b0c8f2d62 100644 --- a/crates/rpc/src/rpc.rs +++ b/crates/rpc/src/rpc.rs @@ -6,4 +6,4 @@ pub use conn::Connection; pub use peer::*; mod macros; -pub const PROTOCOL_VERSION: u32 = 29; +pub const PROTOCOL_VERSION: u32 = 30;