From da7bd8439b5a88cf78da5b0996690661a8b180aa Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 1 Jul 2021 12:54:16 +0200 Subject: [PATCH] Report `SelectionSet` deletion operations correctly --- zed-rpc/proto/zed.proto | 6 +++++- zed/src/editor/buffer.rs | 39 +++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/zed-rpc/proto/zed.proto b/zed-rpc/proto/zed.proto index c2f6929a19..da2a2f40e9 100644 --- a/zed-rpc/proto/zed.proto +++ b/zed-rpc/proto/zed.proto @@ -117,6 +117,10 @@ message Buffer { repeated Operation.Edit history = 3; } +message SelectionSet { + repeated Selection selections = 1; +} + message Selection { uint64 id = 1; Anchor start = 2; @@ -170,7 +174,7 @@ message Operation { uint32 replica_id = 1; uint32 local_timestamp = 2; uint32 lamport_timestamp = 3; - repeated Selection selections = 4; + SelectionSet set = 4; } message SetActiveSelections { diff --git a/zed/src/editor/buffer.rs b/zed/src/editor/buffer.rs index 5404f276c7..210c091ec8 100644 --- a/zed/src/editor/buffer.rs +++ b/zed/src/editor/buffer.rs @@ -2427,8 +2427,8 @@ impl<'a> Into for &'a Operation { replica_id: set_id.replica_id as u32, local_timestamp: set_id.value, lamport_timestamp: lamport_timestamp.value, - selections: selections.as_ref().map_or(Vec::new(), |selections| { - selections + set: selections.as_ref().map(|selections| proto::SelectionSet { + selections: selections .iter() .map(|selection| proto::Selection { id: selection.id as u64, @@ -2436,7 +2436,7 @@ impl<'a> Into for &'a Operation { end: Some((&selection.end).into()), reversed: selection.reversed, }) - .collect() + .collect(), }), }, ), @@ -2538,18 +2538,9 @@ impl TryFrom for Operation { }, }, proto::operation::Variant::UpdateSelections(message) => { - Operation::UpdateSelections { - set_id: time::Lamport { - replica_id: message.replica_id as ReplicaId, - value: message.local_timestamp, - }, - lamport_timestamp: time::Lamport { - replica_id: message.replica_id as ReplicaId, - value: message.lamport_timestamp, - }, - selections: Some( - message - .selections + let selections = if let Some(set) = message.set { + Some( + set.selections .into_iter() .map(|selection| { Ok(Selection { @@ -2566,9 +2557,21 @@ impl TryFrom for Operation { goal: SelectionGoal::None, }) }) - .collect::, anyhow::Error>>()? - .into(), - ), + .collect::, anyhow::Error>>()?, + ) + } else { + None + }; + Operation::UpdateSelections { + set_id: time::Lamport { + replica_id: message.replica_id as ReplicaId, + value: message.local_timestamp, + }, + lamport_timestamp: time::Lamport { + replica_id: message.replica_id as ReplicaId, + value: message.lamport_timestamp, + }, + selections: selections.map(Arc::from), } } proto::operation::Variant::SetActiveSelections(message) => {