@@ -1088,11 +1088,12 @@ fn register_actions(
})
.register_action({
let app_state = app_state.clone();
- move |_workspace, _: &CloseProject, window, cx| {
+ move |workspace, _: &CloseProject, window, cx| {
let Some(window_handle) = window.window_handle().downcast::<MultiWorkspace>() else {
return;
};
let app_state = app_state.clone();
+ let old_group_key = workspace.project_group_key(cx);
cx.spawn_in(window, async move |this, cx| {
let should_continue = this
.update_in(cx, |workspace, window, cx| {
@@ -1131,7 +1132,11 @@ fn register_actions(
},
)
})?;
- task.await
+ task.await?;
+ window_handle.update(cx, |mw, window, cx| {
+ mw.remove_project_group(&old_group_key, window, cx)
+ })?.await.log_err();
+ Ok::<(), anyhow::Error>(())
} else {
Ok(())
}
@@ -6446,4 +6451,55 @@ mod tests {
})
.unwrap();
}
+
+ #[gpui::test]
+ async fn test_close_project_removes_project_group(cx: &mut TestAppContext) {
+ use util::path_list::PathList;
+ use workspace::{OpenMode, ProjectGroupKey};
+
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(path!("/my-project"), json!({}))
+ .await;
+
+ let workspace::OpenResult { window, .. } = cx
+ .update(|cx| {
+ workspace::Workspace::new_local(
+ vec![path!("/my-project").into()],
+ app_state.clone(),
+ None,
+ None,
+ None,
+ OpenMode::Activate,
+ cx,
+ )
+ })
+ .await
+ .unwrap();
+
+ window.update(cx, |mw, _, cx| mw.open_sidebar(cx)).unwrap();
+ cx.background_executor.run_until_parked();
+
+ let project_key = ProjectGroupKey::new(None, PathList::new(&[path!("/my-project")]));
+ let keys = window
+ .read_with(cx, |mw, _| mw.project_group_keys())
+ .unwrap();
+ assert_eq!(
+ keys,
+ vec![project_key],
+ "project group should exist before CloseProject: {keys:?}"
+ );
+
+ cx.dispatch_action(window.into(), CloseProject);
+
+ let keys = window
+ .read_with(cx, |mw, _| mw.project_group_keys())
+ .unwrap();
+ assert!(
+ keys.is_empty(),
+ "project group should be removed after CloseProject: {keys:?}"
+ );
+ }
}