Fixed bugs in workflow step preview (#16445)

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-08-18 22:18:04 -07:00 committed by GitHub
parent 43e13df9f3
commit 86efde4b76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 109 additions and 42 deletions

View file

@ -373,6 +373,7 @@ pub trait ItemHandle: 'static + Send {
fn dragged_tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
fn project_paths(&self, cx: &AppContext) -> SmallVec<[ProjectPath; 3]>;
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[EntityId; 3]>;
fn for_each_project_item(
&self,
@ -531,6 +532,16 @@ impl<T: Item> ItemHandle for View<T> {
result
}
fn project_paths(&self, cx: &AppContext) -> SmallVec<[ProjectPath; 3]> {
let mut result = SmallVec::new();
self.read(cx).for_each_project_item(cx, &mut |_, item| {
if let Some(id) = item.project_path(cx) {
result.push(id);
}
});
result
}
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[EntityId; 3]> {
let mut result = SmallVec::new();
self.read(cx).for_each_project_item(cx, &mut |id, _| {

View file

@ -920,7 +920,22 @@ impl Pane {
cx: &AppContext,
) -> Option<Box<dyn ItemHandle>> {
self.items.iter().find_map(|item| {
if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [entry_id] {
if item.is_singleton(cx) && (item.project_entry_ids(cx).as_slice() == [entry_id]) {
Some(item.boxed_clone())
} else {
None
}
})
}
pub fn item_for_path(
&self,
project_path: ProjectPath,
cx: &AppContext,
) -> Option<Box<dyn ItemHandle>> {
self.items.iter().find_map(move |item| {
if item.is_singleton(cx) && (item.project_path(cx).as_slice() == [project_path.clone()])
{
Some(item.boxed_clone())
} else {
None

View file

@ -2618,6 +2618,33 @@ impl Workspace {
open_project_item
}
pub fn find_project_item<T>(
&self,
pane: &View<Pane>,
project_item: &Model<T::Item>,
cx: &AppContext,
) -> Option<View<T>>
where
T: ProjectItem,
{
use project::Item as _;
let project_item = project_item.read(cx);
let entry_id = project_item.entry_id(cx);
let project_path = project_item.project_path(cx);
let mut item = None;
if let Some(entry_id) = entry_id {
item = pane.read(cx).item_for_entry(entry_id, cx);
}
if item.is_none() {
if let Some(project_path) = project_path {
item = pane.read(cx).item_for_path(project_path, cx);
}
}
item.and_then(|item| item.downcast::<T>())
}
pub fn is_project_item_open<T>(
&self,
pane: &View<Pane>,
@ -2627,13 +2654,7 @@ impl Workspace {
where
T: ProjectItem,
{
use project::Item as _;
project_item
.read(cx)
.entry_id(cx)
.and_then(|entry_id| pane.read(cx).item_for_entry(entry_id, cx))
.and_then(|item| item.downcast::<T>())
self.find_project_item::<T>(pane, project_item, cx)
.is_some()
}
@ -2648,19 +2669,12 @@ impl Workspace {
where
T: ProjectItem,
{
use project::Item as _;
let entry_id = project_item.read(cx).entry_id(cx);
if let Some(item) = entry_id
.and_then(|entry_id| pane.read(cx).item_for_entry(entry_id, cx))
.and_then(|item| item.downcast())
{
if let Some(item) = self.find_project_item(&pane, &project_item, cx) {
self.activate_item(&item, activate_pane, focus_item, cx);
return item;
}
let item = cx.new_view(|cx| T::for_project_item(self.project().clone(), project_item, cx));
let item_id = item.item_id();
let mut destination_index = None;
pane.update(cx, |pane, cx| {