Automatically unfollow when editing, scrolling or changing selections
This commit is contained in:
parent
c550fc3f01
commit
3117554568
14 changed files with 214 additions and 60 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,
|
||||
|
@ -968,7 +968,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
|
||||
|
@ -1161,6 +1161,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() {
|
||||
|
@ -1169,7 +1170,7 @@ impl Buffer {
|
|||
|
||||
self.reparse(cx);
|
||||
|
||||
cx.emit(Event::Edited);
|
||||
cx.emit(Event::Edited { local });
|
||||
if !was_dirty {
|
||||
cx.emit(Event::Dirtied);
|
||||
}
|
||||
|
@ -1206,7 +1207,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();
|
||||
|
@ -1321,7 +1322,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
|
||||
|
@ -1342,7 +1343,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
|
||||
}
|
||||
|
@ -1353,7 +1354,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
|
||||
|
@ -1374,7 +1375,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
|
||||
}
|
||||
|
@ -1440,7 +1441,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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