From 292708573fc2e85602e452bd4551acaeb7f64c7d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 17 Jan 2023 16:13:26 -0800 Subject: [PATCH] Replace MultiBuffer::files with ::for_each_buffer --- crates/editor/src/items.rs | 14 ++++++++------ crates/editor/src/multi_buffer.rs | 12 +++++------- crates/workspace/src/pane.rs | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index f8fa3c9df0e68b0c813616e6480a9a98382866c9..1fe0329405741d87cb7da4da686dfda37aca1116 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.rs index 2347d9a63d1fbaa8d88555c45eb8fe434530138a..c8a62c6a57326683b21515c06f3b3923135c0732 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; 2]> { - let buffers = self.buffers.borrow(); - buffers + pub fn for_each_buffer(&self, mut f: impl FnMut(&ModelHandle)) { + 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.rs index bd355b8b3e75465c17267468202eb8dbffa906cc..735e165c7d644d4842d15e6ae1dfa276585084c8 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -482,7 +482,7 @@ impl Pane { ) -> Box { 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();