Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Replace MultiBuffer::files with ::for_each_buffer
Max Brunsfeld292708573fc2
diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rsindex f8fa3c9df0e..1fe03294057 100644--- a/crates/editor/src/items.rs+++ b/crates/editor/src/items.rs@@ -565,12 +565,14 @@ impl Item for Editor {}fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]> {- self.buffer- .read(cx)- .files(cx)- .into_iter()- .filter_map(|file| File::from_dyn(Some(file))?.project_entry_id(cx))- .collect()+ let mut result = SmallVec::new();+ self.buffer.read(cx).for_each_buffer(|buffer| {+ let buffer = buffer.read(cx);+ if let Some(file) = File::from_dyn(buffer.file()) {+ result.extend(file.project_entry_id(cx));+ }+ });+ result}fn is_singleton(&self, cx: &AppContext) -> bool {diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rsindex 2347d9a63d1..c8a62c6a573 100644--- a/crates/editor/src/multi_buffer.rs+++ b/crates/editor/src/multi_buffer.rs@@ -9,11 +9,10 @@ use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};pub use language::Completion;use language::{char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, CursorShape,- DiagnosticEntry, File, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem,+ DiagnosticEntry, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem,Point, PointUtf16, Selection, TextDimension, ToOffset as _, ToOffsetUtf16 as _, ToPoint as _,ToPointUtf16 as _, TransactionId, Unclipped,};-use smallvec::SmallVec;use std::{borrow::Cow,cell::{Ref, RefCell},@@ -1311,12 +1310,11 @@ impl MultiBuffer {.and_then(|(buffer, offset)| buffer.read(cx).language_at(offset))}- pub fn files<'a>(&'a self, cx: &'a AppContext) -> SmallVec<[&'a Arc<dyn File>; 2]> {- let buffers = self.buffers.borrow();- buffers+ pub fn for_each_buffer(&self, mut f: impl FnMut(&ModelHandle<Buffer>)) {+ self.buffers+ .borrow().values()- .filter_map(|buffer| buffer.buffer.read(cx).file())- .collect()+ .for_each(|state| f(&state.buffer))}pub fn title<'a>(&'a self, cx: &'a AppContext) -> Cow<'a, str> {diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex bd355b8b3e7..735e165c7d6 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -482,7 +482,7 @@ impl Pane {) -> Box<dyn ItemHandle> {let existing_item = pane.update(cx, |pane, cx| {for (index, item) in pane.items.iter().enumerate() {- if item.project_path(cx).is_some()+ if item.is_singleton(cx)&& item.project_entry_ids(cx).as_slice() == [project_entry_id]{let item = item.boxed_clone();