Report SelectionSet deletion operations correctly

This commit is contained in:
Antonio Scandurra 2021-07-01 12:54:16 +02:00
parent c881c7f30f
commit da7bd8439b
2 changed files with 26 additions and 19 deletions

View file

@ -117,6 +117,10 @@ message Buffer {
repeated Operation.Edit history = 3; repeated Operation.Edit history = 3;
} }
message SelectionSet {
repeated Selection selections = 1;
}
message Selection { message Selection {
uint64 id = 1; uint64 id = 1;
Anchor start = 2; Anchor start = 2;
@ -170,7 +174,7 @@ message Operation {
uint32 replica_id = 1; uint32 replica_id = 1;
uint32 local_timestamp = 2; uint32 local_timestamp = 2;
uint32 lamport_timestamp = 3; uint32 lamport_timestamp = 3;
repeated Selection selections = 4; SelectionSet set = 4;
} }
message SetActiveSelections { message SetActiveSelections {

View file

@ -2427,8 +2427,8 @@ impl<'a> Into<proto::Operation> for &'a Operation {
replica_id: set_id.replica_id as u32, replica_id: set_id.replica_id as u32,
local_timestamp: set_id.value, local_timestamp: set_id.value,
lamport_timestamp: lamport_timestamp.value, lamport_timestamp: lamport_timestamp.value,
selections: selections.as_ref().map_or(Vec::new(), |selections| { set: selections.as_ref().map(|selections| proto::SelectionSet {
selections selections: selections
.iter() .iter()
.map(|selection| proto::Selection { .map(|selection| proto::Selection {
id: selection.id as u64, id: selection.id as u64,
@ -2436,7 +2436,7 @@ impl<'a> Into<proto::Operation> for &'a Operation {
end: Some((&selection.end).into()), end: Some((&selection.end).into()),
reversed: selection.reversed, reversed: selection.reversed,
}) })
.collect() .collect(),
}), }),
}, },
), ),
@ -2538,18 +2538,9 @@ impl TryFrom<proto::Operation> for Operation {
}, },
}, },
proto::operation::Variant::UpdateSelections(message) => { proto::operation::Variant::UpdateSelections(message) => {
Operation::UpdateSelections { let selections = if let Some(set) = message.set {
set_id: time::Lamport { Some(
replica_id: message.replica_id as ReplicaId, set.selections
value: message.local_timestamp,
},
lamport_timestamp: time::Lamport {
replica_id: message.replica_id as ReplicaId,
value: message.lamport_timestamp,
},
selections: Some(
message
.selections
.into_iter() .into_iter()
.map(|selection| { .map(|selection| {
Ok(Selection { Ok(Selection {
@ -2566,9 +2557,21 @@ impl TryFrom<proto::Operation> for Operation {
goal: SelectionGoal::None, goal: SelectionGoal::None,
}) })
}) })
.collect::<Result<Vec<_>, anyhow::Error>>()? .collect::<Result<Vec<_>, anyhow::Error>>()?,
.into(), )
), } 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) => { proto::operation::Variant::SetActiveSelections(message) => {