Replace MultiBuffer::files with ::for_each_buffer

This commit is contained in:
Max Brunsfeld
2023-01-17 16:16:44 -08:00
parent f61b870db6
commit 292708573f
3 changed files with 14 additions and 14 deletions
+8 -6
View File
@@ -565,12 +565,14 @@ impl Item for Editor {
} }
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]> { fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]> {
self.buffer let mut result = SmallVec::new();
.read(cx) self.buffer.read(cx).for_each_buffer(|buffer| {
.files(cx) let buffer = buffer.read(cx);
.into_iter() if let Some(file) = File::from_dyn(buffer.file()) {
.filter_map(|file| File::from_dyn(Some(file))?.project_entry_id(cx)) result.extend(file.project_entry_id(cx));
.collect() }
});
result
} }
fn is_singleton(&self, cx: &AppContext) -> bool { fn is_singleton(&self, cx: &AppContext) -> bool {
+5 -7
View File
@@ -9,11 +9,10 @@ use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
pub use language::Completion; pub use language::Completion;
use language::{ use language::{
char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, CursorShape, 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 _, Point, PointUtf16, Selection, TextDimension, ToOffset as _, ToOffsetUtf16 as _, ToPoint as _,
ToPointUtf16 as _, TransactionId, Unclipped, ToPointUtf16 as _, TransactionId, Unclipped,
}; };
use smallvec::SmallVec;
use std::{ use std::{
borrow::Cow, borrow::Cow,
cell::{Ref, RefCell}, cell::{Ref, RefCell},
@@ -1311,12 +1310,11 @@ impl MultiBuffer {
.and_then(|(buffer, offset)| buffer.read(cx).language_at(offset)) .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]> { pub fn for_each_buffer(&self, mut f: impl FnMut(&ModelHandle<Buffer>)) {
let buffers = self.buffers.borrow(); self.buffers
buffers .borrow()
.values() .values()
.filter_map(|buffer| buffer.buffer.read(cx).file()) .for_each(|state| f(&state.buffer))
.collect()
} }
pub fn title<'a>(&'a self, cx: &'a AppContext) -> Cow<'a, str> { pub fn title<'a>(&'a self, cx: &'a AppContext) -> Cow<'a, str> {
+1 -1
View File
@@ -482,7 +482,7 @@ impl Pane {
) -> Box<dyn ItemHandle> { ) -> Box<dyn ItemHandle> {
let existing_item = pane.update(cx, |pane, cx| { let existing_item = pane.update(cx, |pane, cx| {
for (index, item) in pane.items.iter().enumerate() { 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] && item.project_entry_ids(cx).as_slice() == [project_entry_id]
{ {
let item = item.boxed_clone(); let item = item.boxed_clone();