mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Merge pull request #672 from zed-industries/fix-unfollowing-on-edit
Automatically unfollow leader only for edits that originate from the follower editor
This commit is contained in:
commit
ccc276da7a
11 changed files with 563 additions and 463 deletions
File diff suppressed because it is too large
Load diff
|
@ -198,7 +198,7 @@ impl FollowableItem for Editor {
|
|||
|
||||
fn should_unfollow_on_event(event: &Self::Event, _: &AppContext) -> bool {
|
||||
match event {
|
||||
Event::Edited { local } => *local,
|
||||
Event::Edited => true,
|
||||
Event::SelectionsChanged { local } => *local,
|
||||
Event::ScrollPositionChanged { local } => *local,
|
||||
_ => false,
|
||||
|
|
|
@ -291,7 +291,7 @@ impl FileFinder {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
editor::Event::Edited { .. } => {
|
||||
editor::Event::BufferEdited { .. } => {
|
||||
let query = self.query_editor.update(cx, |buffer, cx| buffer.text(cx));
|
||||
if query.is_empty() {
|
||||
self.latest_search_id = post_inc(&mut self.search_count);
|
||||
|
|
|
@ -102,7 +102,7 @@ impl GoToLine {
|
|||
) {
|
||||
match event {
|
||||
editor::Event::Blurred => cx.emit(Event::Dismissed),
|
||||
editor::Event::Edited { .. } => {
|
||||
editor::Event::BufferEdited { .. } => {
|
||||
let line_editor = self.line_editor.read(cx).buffer().read(cx).read(cx).text();
|
||||
let mut components = line_editor.trim().split(&[',', ':'][..]);
|
||||
let row = components.next().and_then(|row| row.parse::<u32>().ok());
|
||||
|
|
|
@ -142,7 +142,7 @@ pub enum Operation {
|
|||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Event {
|
||||
Operation(Operation),
|
||||
Edited { local: bool },
|
||||
Edited,
|
||||
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, true, cx);
|
||||
self.did_edit(&start_version, was_dirty, cx);
|
||||
Some(transaction_id)
|
||||
} else {
|
||||
None
|
||||
|
@ -1160,7 +1160,6 @@ 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 +1168,7 @@ impl Buffer {
|
|||
|
||||
self.reparse(cx);
|
||||
|
||||
cx.emit(Event::Edited { local });
|
||||
cx.emit(Event::Edited);
|
||||
if !was_dirty {
|
||||
cx.emit(Event::Dirtied);
|
||||
}
|
||||
|
@ -1206,7 +1205,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, false, cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
// Notify independently of whether the buffer was edited as the operations could include a
|
||||
// selection update.
|
||||
cx.notify();
|
||||
|
@ -1321,7 +1320,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, true, cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
Some(transaction_id)
|
||||
} else {
|
||||
None
|
||||
|
@ -1342,7 +1341,7 @@ impl Buffer {
|
|||
self.send_operation(Operation::Buffer(operation), cx);
|
||||
}
|
||||
if undone {
|
||||
self.did_edit(&old_version, was_dirty, true, cx)
|
||||
self.did_edit(&old_version, was_dirty, cx)
|
||||
}
|
||||
undone
|
||||
}
|
||||
|
@ -1353,7 +1352,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, true, cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
Some(transaction_id)
|
||||
} else {
|
||||
None
|
||||
|
@ -1374,7 +1373,7 @@ impl Buffer {
|
|||
self.send_operation(Operation::Buffer(operation), cx);
|
||||
}
|
||||
if redone {
|
||||
self.did_edit(&old_version, was_dirty, true, cx)
|
||||
self.did_edit(&old_version, was_dirty, cx)
|
||||
}
|
||||
redone
|
||||
}
|
||||
|
@ -1440,7 +1439,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, true, cx);
|
||||
self.did_edit(&old_version, was_dirty, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,19 +122,11 @@ fn test_edit_events(cx: &mut gpui::MutableAppContext) {
|
|||
let buffer_1_events = buffer_1_events.borrow();
|
||||
assert_eq!(
|
||||
*buffer_1_events,
|
||||
vec![
|
||||
Event::Edited { local: true },
|
||||
Event::Dirtied,
|
||||
Event::Edited { local: true },
|
||||
Event::Edited { local: true }
|
||||
]
|
||||
vec![Event::Edited, Event::Dirtied, Event::Edited, Event::Edited]
|
||||
);
|
||||
|
||||
let buffer_2_events = buffer_2_events.borrow();
|
||||
assert_eq!(
|
||||
*buffer_2_events,
|
||||
vec![Event::Edited { local: false }, Event::Dirtied]
|
||||
);
|
||||
assert_eq!(*buffer_2_events, vec![Event::Edited, Event::Dirtied]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
|
|
@ -224,7 +224,7 @@ impl OutlineView {
|
|||
) {
|
||||
match event {
|
||||
editor::Event::Blurred => cx.emit(Event::Dismissed),
|
||||
editor::Event::Edited { .. } => self.update_matches(cx),
|
||||
editor::Event::BufferEdited { .. } => self.update_matches(cx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6229,10 +6229,7 @@ mod tests {
|
|||
assert!(buffer.is_dirty());
|
||||
assert_eq!(
|
||||
*events.borrow(),
|
||||
&[
|
||||
language::Event::Edited { local: true },
|
||||
language::Event::Dirtied
|
||||
]
|
||||
&[language::Event::Edited, language::Event::Dirtied]
|
||||
);
|
||||
events.borrow_mut().clear();
|
||||
buffer.did_save(buffer.version(), buffer.file().unwrap().mtime(), None, cx);
|
||||
|
@ -6255,9 +6252,9 @@ mod tests {
|
|||
assert_eq!(
|
||||
*events.borrow(),
|
||||
&[
|
||||
language::Event::Edited { local: true },
|
||||
language::Event::Edited,
|
||||
language::Event::Dirtied,
|
||||
language::Event::Edited { local: true },
|
||||
language::Event::Edited,
|
||||
],
|
||||
);
|
||||
events.borrow_mut().clear();
|
||||
|
@ -6269,7 +6266,7 @@ mod tests {
|
|||
assert!(buffer.is_dirty());
|
||||
});
|
||||
|
||||
assert_eq!(*events.borrow(), &[language::Event::Edited { local: true }]);
|
||||
assert_eq!(*events.borrow(), &[language::Event::Edited]);
|
||||
|
||||
// When a file is deleted, the buffer is considered dirty.
|
||||
let events = Rc::new(RefCell::new(Vec::new()));
|
||||
|
|
|
@ -328,7 +328,7 @@ impl ProjectSymbolsView {
|
|||
) {
|
||||
match event {
|
||||
editor::Event::Blurred => cx.emit(Event::Dismissed),
|
||||
editor::Event::Edited { .. } => self.update_matches(cx),
|
||||
editor::Event::BufferEdited { .. } => self.update_matches(cx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -360,7 +360,7 @@ impl SearchBar {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
editor::Event::Edited { .. } => {
|
||||
editor::Event::BufferEdited { .. } => {
|
||||
self.query_contains_error = false;
|
||||
self.clear_matches(cx);
|
||||
self.update_matches(true, cx);
|
||||
|
@ -377,7 +377,7 @@ impl SearchBar {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
editor::Event::Edited { .. } => self.update_matches(false, cx),
|
||||
editor::Event::BufferEdited { .. } => self.update_matches(false, cx),
|
||||
editor::Event::SelectionsChanged { .. } => self.update_match_index(cx),
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ impl ThemeSelector {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
editor::Event::Edited { .. } => {
|
||||
editor::Event::BufferEdited { .. } => {
|
||||
self.update_matches(cx);
|
||||
self.select_if_matching(&cx.global::<Settings>().theme.name);
|
||||
self.show_selected_theme(cx);
|
||||
|
|
Loading…
Reference in a new issue