Allow creating entries when nothing is selected in the project panel (#29336)

Closes https://github.com/zed-industries/zed/issues/29249

Release Notes:

- Allowed creating entries when nothing is selected in the project panel
This commit is contained in:
Kirill Bulatov 2025-04-24 11:46:35 +03:00 committed by GitHub
parent c0f8e0f605
commit fcfeea4825
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 134 additions and 51 deletions

View file

@ -4948,6 +4948,71 @@ async fn test_collapse_all_for_entry(cx: &mut gpui::TestAppContext) {
}
}
#[gpui::test]
async fn test_create_entries_without_selection(cx: &mut gpui::TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.executor().clone());
fs.insert_tree(
path!("/root"),
json!({
"dir1": {
"file1.txt": "",
},
}),
)
.await;
let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;
let workspace = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
let cx = &mut VisualTestContext::from_window(*workspace, cx);
let panel = workspace
.update(cx, |workspace, window, cx| {
let panel = ProjectPanel::new(workspace, window, cx);
workspace.add_panel(panel.clone(), window, cx);
panel
})
.unwrap();
#[rustfmt::skip]
assert_eq!(
visible_entries_as_strings(&panel, 0..20, cx),
&[
separator!("v root"),
separator!(" > dir1"),
],
"Initial state with nothing selected"
);
panel.update_in(cx, |panel, window, cx| {
panel.new_file(&NewFile, window, cx);
});
panel.update_in(cx, |panel, window, cx| {
assert!(panel.filename_editor.read(cx).is_focused(window));
});
panel
.update_in(cx, |panel, window, cx| {
panel.filename_editor.update(cx, |editor, cx| {
editor.set_text("hello_from_no_selections", window, cx)
});
panel.confirm_edit(window, cx).unwrap()
})
.await
.unwrap();
#[rustfmt::skip]
assert_eq!(
visible_entries_as_strings(&panel, 0..20, cx),
&[
separator!("v root"),
separator!(" > dir1"),
separator!(" hello_from_no_selections <== selected <== marked"),
],
"A new file is created under the root directory"
);
}
fn select_path(panel: &Entity<ProjectPanel>, path: impl AsRef<Path>, cx: &mut VisualTestContext) {
let path = path.as_ref();
panel.update(cx, |panel, cx| {