WIP line mode operations
This commit is contained in:
parent
8044586296
commit
d7d17b2148
15 changed files with 166 additions and 30 deletions
|
@ -83,6 +83,7 @@ pub struct BufferSnapshot {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
struct SelectionSet {
|
||||
line_mode: bool,
|
||||
selections: Arc<[Selection<Anchor>]>,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
}
|
||||
|
@ -129,6 +130,7 @@ pub enum Operation {
|
|||
UpdateSelections {
|
||||
selections: Arc<[Selection<Anchor>]>,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
line_mode: bool,
|
||||
},
|
||||
UpdateCompletionTriggers {
|
||||
triggers: Vec<String>,
|
||||
|
@ -343,6 +345,7 @@ impl Buffer {
|
|||
this.remote_selections.insert(
|
||||
selection_set.replica_id as ReplicaId,
|
||||
SelectionSet {
|
||||
line_mode: selection_set.line_mode,
|
||||
selections: proto::deserialize_selections(selection_set.selections),
|
||||
lamport_timestamp,
|
||||
},
|
||||
|
@ -385,6 +388,7 @@ impl Buffer {
|
|||
replica_id: *replica_id as u32,
|
||||
selections: proto::serialize_selections(&set.selections),
|
||||
lamport_timestamp: set.lamport_timestamp.value,
|
||||
line_mode: set.line_mode,
|
||||
})
|
||||
.collect(),
|
||||
diagnostics: proto::serialize_diagnostics(self.diagnostics.iter()),
|
||||
|
@ -1030,6 +1034,7 @@ impl Buffer {
|
|||
pub fn set_active_selections(
|
||||
&mut self,
|
||||
selections: Arc<[Selection<Anchor>]>,
|
||||
line_mode: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||
|
@ -1038,11 +1043,13 @@ impl Buffer {
|
|||
SelectionSet {
|
||||
selections: selections.clone(),
|
||||
lamport_timestamp,
|
||||
line_mode,
|
||||
},
|
||||
);
|
||||
self.send_operation(
|
||||
Operation::UpdateSelections {
|
||||
selections,
|
||||
line_mode,
|
||||
lamport_timestamp,
|
||||
},
|
||||
cx,
|
||||
|
@ -1050,7 +1057,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
pub fn remove_active_selections(&mut self, cx: &mut ModelContext<Self>) {
|
||||
self.set_active_selections(Arc::from([]), cx);
|
||||
self.set_active_selections(Arc::from([]), false, cx);
|
||||
}
|
||||
|
||||
pub fn set_text<T>(&mut self, text: T, cx: &mut ModelContext<Self>) -> Option<clock::Local>
|
||||
|
@ -1287,6 +1294,7 @@ impl Buffer {
|
|||
Operation::UpdateSelections {
|
||||
selections,
|
||||
lamport_timestamp,
|
||||
line_mode,
|
||||
} => {
|
||||
if let Some(set) = self.remote_selections.get(&lamport_timestamp.replica_id) {
|
||||
if set.lamport_timestamp > lamport_timestamp {
|
||||
|
@ -1299,6 +1307,7 @@ impl Buffer {
|
|||
SelectionSet {
|
||||
selections,
|
||||
lamport_timestamp,
|
||||
line_mode,
|
||||
},
|
||||
);
|
||||
self.text.lamport_clock.observe(lamport_timestamp);
|
||||
|
@ -1890,8 +1899,14 @@ impl BufferSnapshot {
|
|||
pub fn remote_selections_in_range<'a>(
|
||||
&'a self,
|
||||
range: Range<Anchor>,
|
||||
) -> impl 'a + Iterator<Item = (ReplicaId, impl 'a + Iterator<Item = &'a Selection<Anchor>>)>
|
||||
{
|
||||
) -> impl 'a
|
||||
+ Iterator<
|
||||
Item = (
|
||||
ReplicaId,
|
||||
bool,
|
||||
impl 'a + Iterator<Item = &'a Selection<Anchor>>,
|
||||
),
|
||||
> {
|
||||
self.remote_selections
|
||||
.iter()
|
||||
.filter(|(replica_id, set)| {
|
||||
|
@ -1909,7 +1924,11 @@ impl BufferSnapshot {
|
|||
Ok(ix) | Err(ix) => ix,
|
||||
};
|
||||
|
||||
(*replica_id, set.selections[start_ix..end_ix].iter())
|
||||
(
|
||||
*replica_id,
|
||||
set.line_mode,
|
||||
set.selections[start_ix..end_ix].iter(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,13 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation {
|
|||
}),
|
||||
Operation::UpdateSelections {
|
||||
selections,
|
||||
line_mode,
|
||||
lamport_timestamp,
|
||||
} => proto::operation::Variant::UpdateSelections(proto::operation::UpdateSelections {
|
||||
replica_id: lamport_timestamp.replica_id as u32,
|
||||
lamport_timestamp: lamport_timestamp.value,
|
||||
selections: serialize_selections(selections),
|
||||
line_mode: *line_mode,
|
||||
}),
|
||||
Operation::UpdateDiagnostics {
|
||||
diagnostics,
|
||||
|
@ -217,6 +219,7 @@ pub fn deserialize_operation(message: proto::Operation) -> Result<Operation> {
|
|||
value: message.lamport_timestamp,
|
||||
},
|
||||
selections: Arc::from(selections),
|
||||
line_mode: message.line_mode,
|
||||
}
|
||||
}
|
||||
proto::operation::Variant::UpdateDiagnostics(message) => Operation::UpdateDiagnostics {
|
||||
|
|
|
@ -828,7 +828,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
|
|||
selections
|
||||
);
|
||||
active_selections.insert(replica_id, selections.clone());
|
||||
buffer.set_active_selections(selections, cx);
|
||||
buffer.set_active_selections(selections, false, cx);
|
||||
});
|
||||
mutation_count -= 1;
|
||||
}
|
||||
|
@ -984,7 +984,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
|
|||
let buffer = buffer.read(cx).snapshot();
|
||||
let actual_remote_selections = buffer
|
||||
.remote_selections_in_range(Anchor::MIN..Anchor::MAX)
|
||||
.map(|(replica_id, selections)| (replica_id, selections.collect::<Vec<_>>()))
|
||||
.map(|(replica_id, _, selections)| (replica_id, selections.collect::<Vec<_>>()))
|
||||
.collect::<Vec<_>>();
|
||||
let expected_remote_selections = active_selections
|
||||
.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue