Merge pull request #661 from zed-industries/follow
Introduce basic following experience
This commit is contained in:
commit
004f98cc6d
35 changed files with 3061 additions and 510 deletions
|
@ -142,7 +142,7 @@ pub enum Operation {
|
|||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Event {
|
||||
Operation(Operation),
|
||||
Edited,
|
||||
Edited { local: bool },
|
||||
Dirtied,
|
||||
Saved,
|
||||
FileHandleChanged,
|
||||
|
@ -967,7 +967,7 @@ impl Buffer {
|
|||
) -> Option<TransactionId> {
|
||||
if let Some((transaction_id, start_version)) = self.text.end_transaction_at(now) {
|
||||
let was_dirty = start_version != self.saved_version;
|
||||
self.did_edit(&start_version, was_dirty, cx);
|
||||
self.did_edit(&start_version, was_dirty, true, cx);
|
||||
Some(transaction_id)
|
||||
} else {
|
||||
None
|
||||
|
@ -1160,6 +1160,7 @@ impl Buffer {
|
|||
&mut self,
|
||||
old_version: &clock::Global,
|
||||
was_dirty: bool,
|
||||
local: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
if self.edits_since::<usize>(old_version).next().is_none() {
|
||||
|
@ -1168,7 +1169,7 @@ impl Buffer {
|
|||
|
||||
self.reparse(cx);
|
||||
|
||||
cx.emit(Event::Edited);
|
||||
cx.emit(Event::Edited { local });
|
||||
if !was_dirty {
|
||||
cx.emit(Event::Dirtied);
|
||||
}
|
||||
|
@ -1205,7 +1206,7 @@ impl Buffer {
|
|||
self.text.apply_ops(buffer_ops)?;
|
||||
self.deferred_ops.insert(deferred_ops);
|
||||
self.flush_deferred_ops(cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
self.did_edit(&old_version, was_dirty, false, cx);
|
||||
// Notify independently of whether the buffer was edited as the operations could include a
|
||||
// selection update.
|
||||
cx.notify();
|
||||
|
@ -1320,7 +1321,7 @@ impl Buffer {
|
|||
|
||||
if let Some((transaction_id, operation)) = self.text.undo() {
|
||||
self.send_operation(Operation::Buffer(operation), cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
self.did_edit(&old_version, was_dirty, true, cx);
|
||||
Some(transaction_id)
|
||||
} else {
|
||||
None
|
||||
|
@ -1341,7 +1342,7 @@ impl Buffer {
|
|||
self.send_operation(Operation::Buffer(operation), cx);
|
||||
}
|
||||
if undone {
|
||||
self.did_edit(&old_version, was_dirty, cx)
|
||||
self.did_edit(&old_version, was_dirty, true, cx)
|
||||
}
|
||||
undone
|
||||
}
|
||||
|
@ -1352,7 +1353,7 @@ impl Buffer {
|
|||
|
||||
if let Some((transaction_id, operation)) = self.text.redo() {
|
||||
self.send_operation(Operation::Buffer(operation), cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
self.did_edit(&old_version, was_dirty, true, cx);
|
||||
Some(transaction_id)
|
||||
} else {
|
||||
None
|
||||
|
@ -1373,7 +1374,7 @@ impl Buffer {
|
|||
self.send_operation(Operation::Buffer(operation), cx);
|
||||
}
|
||||
if redone {
|
||||
self.did_edit(&old_version, was_dirty, cx)
|
||||
self.did_edit(&old_version, was_dirty, true, cx)
|
||||
}
|
||||
redone
|
||||
}
|
||||
|
@ -1439,7 +1440,7 @@ impl Buffer {
|
|||
if !ops.is_empty() {
|
||||
for op in ops {
|
||||
self.send_operation(Operation::Buffer(op), cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
self.did_edit(&old_version, was_dirty, true, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1800,12 +1801,6 @@ impl BufferSnapshot {
|
|||
.min_by_key(|(open_range, close_range)| close_range.end - open_range.start)
|
||||
}
|
||||
|
||||
/*
|
||||
impl BufferSnapshot
|
||||
pub fn remote_selections_in_range(&self, Range<Anchor>) -> impl Iterator<Item = (ReplicaId, impl Iterator<Item = &Selection<Anchor>>)>
|
||||
pub fn remote_selections_in_range(&self, Range<Anchor>) -> impl Iterator<Item = (ReplicaId, i
|
||||
*/
|
||||
|
||||
pub fn remote_selections_in_range<'a>(
|
||||
&'a self,
|
||||
range: Range<Anchor>,
|
||||
|
|
|
@ -100,15 +100,16 @@ pub fn serialize_undo_map_entry(
|
|||
}
|
||||
|
||||
pub fn serialize_selections(selections: &Arc<[Selection<Anchor>]>) -> Vec<proto::Selection> {
|
||||
selections
|
||||
.iter()
|
||||
.map(|selection| proto::Selection {
|
||||
id: selection.id as u64,
|
||||
start: Some(serialize_anchor(&selection.start)),
|
||||
end: Some(serialize_anchor(&selection.end)),
|
||||
reversed: selection.reversed,
|
||||
})
|
||||
.collect()
|
||||
selections.iter().map(serialize_selection).collect()
|
||||
}
|
||||
|
||||
pub fn serialize_selection(selection: &Selection<Anchor>) -> proto::Selection {
|
||||
proto::Selection {
|
||||
id: selection.id as u64,
|
||||
start: Some(serialize_anchor(&selection.start)),
|
||||
end: Some(serialize_anchor(&selection.end)),
|
||||
reversed: selection.reversed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize_diagnostics<'a>(
|
||||
|
@ -274,19 +275,21 @@ pub fn deserialize_selections(selections: Vec<proto::Selection>) -> Arc<[Selecti
|
|||
Arc::from(
|
||||
selections
|
||||
.into_iter()
|
||||
.filter_map(|selection| {
|
||||
Some(Selection {
|
||||
id: selection.id as usize,
|
||||
start: deserialize_anchor(selection.start?)?,
|
||||
end: deserialize_anchor(selection.end?)?,
|
||||
reversed: selection.reversed,
|
||||
goal: SelectionGoal::None,
|
||||
})
|
||||
})
|
||||
.filter_map(deserialize_selection)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn deserialize_selection(selection: proto::Selection) -> Option<Selection<Anchor>> {
|
||||
Some(Selection {
|
||||
id: selection.id as usize,
|
||||
start: deserialize_anchor(selection.start?)?,
|
||||
end: deserialize_anchor(selection.end?)?,
|
||||
reversed: selection.reversed,
|
||||
goal: SelectionGoal::None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn deserialize_diagnostics(
|
||||
diagnostics: Vec<proto::Diagnostic>,
|
||||
) -> Arc<[DiagnosticEntry<Anchor>]> {
|
||||
|
|
|
@ -122,11 +122,19 @@ fn test_edit_events(cx: &mut gpui::MutableAppContext) {
|
|||
let buffer_1_events = buffer_1_events.borrow();
|
||||
assert_eq!(
|
||||
*buffer_1_events,
|
||||
vec![Event::Edited, Event::Dirtied, Event::Edited, Event::Edited]
|
||||
vec![
|
||||
Event::Edited { local: true },
|
||||
Event::Dirtied,
|
||||
Event::Edited { local: true },
|
||||
Event::Edited { local: true }
|
||||
]
|
||||
);
|
||||
|
||||
let buffer_2_events = buffer_2_events.borrow();
|
||||
assert_eq!(*buffer_2_events, vec![Event::Edited, Event::Dirtied]);
|
||||
assert_eq!(
|
||||
*buffer_2_events,
|
||||
vec![Event::Edited { local: false }, Event::Dirtied]
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue