diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index 6c4775ba6d..eacbf44add 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -3832,14 +3832,14 @@ mod tests { .unwrap() }); code_action_editor.update(cx_b, |editor, cx| { - assert_eq!(editor.text(cx), "\nmod other;\nfn main() { let foo = 4; }"); + assert_eq!(editor.text(cx), "mod other;\nfn main() { let foo = 4; }\n"); editor.undo(&Undo, cx); assert_eq!( editor.text(cx), - "pub fn foo() -> usize { 4 }\nmod other;\nfn main() { let foo = other::foo(); }" + "mod other;\nfn main() { let foo = other::foo(); }\npub fn foo() -> usize { 4 }" ); editor.redo(&Redo, cx); - assert_eq!(editor.text(cx), "\nmod other;\nfn main() { let foo = 4; }"); + assert_eq!(editor.text(cx), "mod other;\nfn main() { let foo = 4; }\n"); }); } @@ -4037,17 +4037,17 @@ mod tests { rename_editor.update(cx_b, |editor, cx| { assert_eq!( editor.text(cx), - "const TWO: usize = one::THREE + one::THREE;\nconst THREE: usize = 1;" + "const THREE: usize = 1;\nconst TWO: usize = one::THREE + one::THREE;" ); editor.undo(&Undo, cx); assert_eq!( editor.text(cx), - "const TWO: usize = one::ONE + one::ONE;\nconst ONE: usize = 1;" + "const ONE: usize = 1;\nconst TWO: usize = one::ONE + one::ONE;" ); editor.redo(&Redo, cx); assert_eq!( editor.text(cx), - "const TWO: usize = one::THREE + one::THREE;\nconst THREE: usize = 1;" + "const THREE: usize = 1;\nconst TWO: usize = one::THREE + one::THREE;" ); }); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index f60cf7eb9a..e3e7093007 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2499,11 +2499,16 @@ impl Editor { ) -> Result<()> { let replica_id = this.read_with(&cx, |this, cx| this.replica_id(cx)); + let mut entries = transaction.0.into_iter().collect::>(); + entries.sort_unstable_by_key(|(buffer, _)| { + buffer.read_with(&cx, |buffer, _| buffer.file().map(|f| f.path().clone())) + }); + // If the project transaction's edits are all contained within this editor, then // avoid opening a new editor to display them. - let mut entries = transaction.0.iter(); - if let Some((buffer, transaction)) = entries.next() { - if entries.next().is_none() { + + if let Some((buffer, transaction)) = entries.first() { + if entries.len() == 1 { let excerpt = this.read_with(&cx, |editor, cx| { editor .buffer() @@ -2532,7 +2537,7 @@ impl Editor { let mut ranges_to_highlight = Vec::new(); let excerpt_buffer = cx.add_model(|cx| { let mut multibuffer = MultiBuffer::new(replica_id).with_title(title); - for (buffer, transaction) in &transaction.0 { + for (buffer, transaction) in &entries { let snapshot = buffer.read(cx).snapshot(); ranges_to_highlight.extend( multibuffer.push_excerpts_with_context_lines( @@ -2545,7 +2550,7 @@ impl Editor { ), ); } - multibuffer.push_transaction(&transaction.0); + multibuffer.push_transaction(entries.iter().map(|(b, t)| (b, t))); multibuffer });