Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Allow opening README files by default (#65389)

Kirill Bulatov5d47f835421d
diff --git a/assets/settings/default.json b/assets/settings/default.json
index ed88af25e32..8172ebde474 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -218,11 +218,14 @@
// "when_closing_with_no_tabs": "keep_window_open",
"when_closing_with_no_tabs": "platform_default",
// What to show when opening a new window.
- // May take 2 values:
+ // May take 3 values:
// 1. Show an empty untitled buffer
// "on_new_window": "empty_tab"
// 2. Show the launchpad with recent projects
// "on_new_window": "launchpad"
+ // 3. Open a root-level README in a preview tab when the project has no open items.
+ // Leave the pane empty if no README is found.
+ // "on_new_window": "readme"
"on_new_window": "launchpad",
// What to do when the last window is closed.
// May take 2 values:
diff --git a/crates/settings_content/src/workspace.rs b/crates/settings_content/src/workspace.rs
index 15b2f84ecc7..6d3c9581a77 100644
--- a/crates/settings_content/src/workspace.rs
+++ b/crates/settings_content/src/workspace.rs
@@ -114,7 +114,7 @@ pub struct WorkspaceSettingsContent {
/// Default: none
pub max_tabs: Option<NonZeroUsize>,
/// What to show when opening a new window.
- /// Values: empty_tab, launchpad
+ /// Values: empty_tab, launchpad, readme
/// Default: launchpad
pub on_new_window: Option<OnNewWindow>,
/// What to do when the last window is closed
@@ -738,6 +738,9 @@ pub enum OnNewWindow {
/// Show the launchpad with recent projects when opening a new window
#[default]
Launchpad,
+ /// Open a root-level README in a preview tab when opening a project with no open items.
+ /// Leave the pane empty if no README is found.
+ Readme,
}
#[derive(
diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs
index 138acacbc81..eefb373eb85 100644
--- a/crates/settings_ui/src/page_data.rs
+++ b/crates/settings_ui/src/page_data.rs
@@ -174,7 +174,7 @@ fn general_page(cx: &App) -> SettingsPage {
}),
SettingsPageItem::SettingItem(SettingItem {
title: "On New Window",
- description: "What to show when opening a new window.",
+ description: "What to show when opening a new window; Readme opens a project's README when no items are open, leaving the pane empty if none is found.",
field: Box::new(SettingField {
organization_override: None,
json_path: Some("on_new_window"),
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index 6ddb3431056..4b1942a7be5 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -2372,6 +2372,7 @@ impl Workspace {
.map(|ws| !ws.paths.is_empty())
.unwrap_or(false);
+ let all_paths_resolved = project_paths.iter().all(|(_, path)| path.is_some());
let opened_items = window
.update(cx, |_, window, cx| {
workspace.update(cx, |_workspace: &mut Workspace, cx| {
@@ -2381,6 +2382,16 @@ impl Workspace {
.await
.unwrap_or_default();
+ if all_paths_resolved
+ && !opened_items.is_empty()
+ && opened_items.iter().all(Option::is_none)
+ && let Ok(task) = window.update(cx, |_, window, cx| {
+ workspace.update(cx, |workspace, cx| workspace.open_readme(window, cx))
+ })
+ {
+ task.await;
+ }
+
// Restore default dock state for empty workspaces
// Only restore if:
// 1. This is an empty workspace (no paths), AND
@@ -4021,7 +4032,7 @@ impl Workspace {
// Sort the paths to ensure we add worktrees for parents before their children.
abs_paths.sort_unstable();
- cx.spawn_in(window, async move |this, cx| {
+ cx.spawn_in(window, async move |workspace, cx| {
let mut tasks = Vec::with_capacity(abs_paths.len());
for abs_path in &abs_paths {
@@ -4040,16 +4051,16 @@ impl Workspace {
},
};
let project_path = match visible {
- Some(visible) => match this
- .update(cx, |this, cx| {
+ Some(visible) => match workspace
+ .update(cx, |workspace, cx| {
Workspace::project_path_for_path(
- this.project.clone(),
+ workspace.project.clone(),
abs_path,
visible,
cx,
)
})
- .log_err()
+ .ok()
{
Some(project_path) => project_path.await.log_err(),
None => None,
@@ -4057,7 +4068,7 @@ impl Workspace {
None => None,
};
- let this = this.clone();
+ let workspace = workspace.clone();
let abs_path: Arc<Path> = SanitizedPath::new(&abs_path).as_path().into();
let fs = fs.clone();
let pane = pane.clone();
@@ -4084,17 +4095,18 @@ impl Workspace {
None
} else {
Some(
- this.update_in(cx, |this, window, cx| {
- this.open_path(
- project_path,
- pane,
- options.focus.unwrap_or(true),
- window,
- cx,
- )
- })
- .ok()?
- .await,
+ workspace
+ .update_in(cx, |workspace, window, cx| {
+ workspace.open_path(
+ project_path,
+ pane,
+ options.focus.unwrap_or(true),
+ window,
+ cx,
+ )
+ })
+ .ok()?
+ .await,
)
}
});
@@ -4135,7 +4147,7 @@ impl Workspace {
OpenVisible::OnlyDirectories => winner_is_dir,
};
- let Some(worktree_task) = this
+ let Some(worktree_task) = workspace
.update(cx, |workspace, cx| {
workspace.project.update(cx, |project, cx| {
project.find_or_create_worktree(
@@ -4154,7 +4166,7 @@ impl Workspace {
break 'emit_winner;
};
- let Ok(Some(entry_id)) = this.update(cx, |_, cx| {
+ let Ok(Some(entry_id)) = workspace.update(cx, |_, cx| {
let worktree = worktree.read(cx);
let worktree_abs_path = worktree.abs_path();
let entry = if winner_abs_path.as_ref() == worktree_abs_path.as_ref() {
@@ -4175,12 +4187,13 @@ impl Workspace {
break 'emit_winner;
};
- this.update(cx, |workspace, cx| {
- workspace.project.update(cx, |_, cx| {
- cx.emit(project::Event::ActiveEntryChanged(Some(entry_id)));
- });
- })
- .ok();
+ workspace
+ .update(cx, |workspace, cx| {
+ workspace.project.update(cx, |_, cx| {
+ cx.emit(project::Event::ActiveEntryChanged(Some(entry_id)));
+ });
+ })
+ .ok();
}
}
@@ -5322,6 +5335,94 @@ impl Workspace {
})
}
+ fn open_readme(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Task<()> {
+ if WorkspaceSettings::get_global(cx).on_new_window != settings::OnNewWindow::Readme
+ || self.items(cx).next().is_some()
+ {
+ return Task::ready(());
+ }
+
+ let project = self.project.clone();
+ let mut candidates = Vec::new();
+ for worktree in project.read(cx).visible_worktrees(cx) {
+ let worktree = worktree.read(cx);
+ for file_name in [
+ "README.md",
+ "readme.md",
+ "Readme.md",
+ "README",
+ "readme",
+ "Readme",
+ "README.txt",
+ "readme.txt",
+ "Readme.txt",
+ ] {
+ let Some(path) = RelPath::from_unix_str(file_name).ok() else {
+ continue;
+ };
+ let metadata = project
+ .read(cx)
+ .resolve_abs_path(&worktree.absolutize(path).to_string_lossy(), cx);
+ let path = ProjectPath {
+ worktree_id: worktree.id(),
+ path: Arc::from(path),
+ };
+ candidates.push((path, metadata));
+ }
+ }
+ let pane = self.active_pane().downgrade();
+ cx.spawn_in(window, async move |workspace, cx| {
+ for (path, metadata) in candidates {
+ if !metadata.await.is_some_and(|metadata| metadata.is_file()) {
+ continue;
+ }
+ let worktree_id = path.worktree_id;
+ let Ok(Some(task)) = workspace.update_in(cx, |workspace, window, cx| {
+ if WorkspaceSettings::get_global(cx).on_new_window
+ != settings::OnNewWindow::Readme
+ || workspace.items(cx).next().is_some()
+ || project.read(cx).worktree_for_id(worktree_id, cx).is_none()
+ || pane.upgrade().is_none()
+ {
+ return None;
+ }
+ Some(workspace.load_path(path.clone(), window, cx))
+ }) else {
+ return;
+ };
+ let (entry_id, build_item) = match task.await {
+ Ok(loaded) => loaded,
+ Err(error) => {
+ log::debug!("Skipping README candidate {path:?}: {error:#}");
+ continue;
+ }
+ };
+ workspace
+ .update_in(cx, |workspace, window, cx| {
+ if WorkspaceSettings::get_global(cx).on_new_window
+ != settings::OnNewWindow::Readme
+ || workspace.items(cx).next().is_some()
+ || project.read(cx).worktree_for_id(worktree_id, cx).is_none()
+ {
+ return;
+ }
+ let Some(pane) = pane.upgrade() else {
+ return;
+ };
+ let focus_item = workspace.owns_window_chrome();
+ pane.update(cx, |pane, cx| {
+ pane.open_item(
+ entry_id, path, focus_item, true, true, None, window, cx,
+ build_item,
+ );
+ });
+ })
+ .ok();
+ return;
+ }
+ })
+ }
+
fn load_path(
&mut self,
path: ProjectPath,
@@ -11146,7 +11247,7 @@ pub fn open_workspace_by_id(
window
.update(cx, |_, window, cx| {
workspace.update(cx, |_workspace, cx| {
- open_items(Some(serialized_workspace), vec![], window, cx)
+ open_items(Some(serialized_workspace), Vec::new(), window, cx)
})
})?
.await?;
@@ -11629,6 +11730,15 @@ async fn open_remote_project_inner(
})?
.await?;
+ if project_path_errors.is_empty()
+ && items.iter().all(Option::is_none)
+ && let Ok(task) = window.update(cx, |_, window, cx| {
+ workspace.update(cx, |workspace, cx| workspace.open_readme(window, cx))
+ })
+ {
+ task.await;
+ }
+
workspace.update(cx, |workspace, cx| {
for error in project_path_errors {
if error.error_code() == proto::ErrorCode::DevServerProjectPathDoesNotExist {
diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs
index ce57d405111..54994b832b6 100644
--- a/crates/zed/src/zed.rs
+++ b/crates/zed/src/zed.rs
@@ -2420,7 +2420,7 @@ fn initialize_new_window(
window: &mut Window,
cx: &mut Context<Workspace>,
) {
- if WorkspaceSettings::get_global(cx).on_new_window == settings::OnNewWindow::Launchpad {
+ if WorkspaceSettings::get_global(cx).on_new_window != settings::OnNewWindow::EmptyTab {
return;
}
// Create buffer synchronously to avoid flicker
@@ -3802,47 +3802,353 @@ mod tests {
}
#[gpui::test]
- async fn test_new_window_launchpad_opens_without_items(cx: &mut TestAppContext) {
+ async fn test_new_window_initial_items(cx: &mut TestAppContext) {
let app_state = init_test(cx);
- cx.update(|cx| {
- SettingsStore::update_global(cx, |store, cx| {
- store.update_user_settings(cx, |settings| {
- settings.workspace.on_new_window = Some(settings::OnNewWindow::Launchpad);
- });
+ for on_new_window in [
+ settings::OnNewWindow::Launchpad,
+ settings::OnNewWindow::Readme,
+ settings::OnNewWindow::EmptyTab,
+ ] {
+ set_on_new_window(Some(on_new_window), cx);
+ cx.update(|cx| {
+ open_new(
+ OpenOptions::default(),
+ app_state.clone(),
+ cx,
+ initialize_new_window,
+ )
+ })
+ .await
+ .expect("open blank window");
+ cx.run_until_parked();
+
+ let window = cx
+ .windows()
+ .first()
+ .expect("blank window")
+ .downcast::<MultiWorkspace>()
+ .expect("workspace window");
+ window
+ .update(cx, |multi_workspace, window, cx| {
+ let workspace = multi_workspace.workspace().read(cx);
+ let expected_items =
+ usize::from(on_new_window == settings::OnNewWindow::EmptyTab);
+ assert_eq!(workspace.items(cx).count(), expected_items);
+ assert_eq!(workspace.active_pane().read(cx).items_len(), expected_items);
+ if expected_items == 1 {
+ let editor = workspace
+ .active_item_as::<Editor>(cx)
+ .expect("empty editor");
+ assert_eq!(editor.read(cx).text(cx), "");
+ }
+ window.remove_window();
+ })
+ .expect("read blank window");
+ cx.run_until_parked();
+ }
+ }
+
+ #[gpui::test]
+ async fn test_open_paths_readme_selection(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/root"),
+ json!({
+ "default": {"README.md": ""},
+ "empty_tab": {"README.md": ""},
+ "markdown": {"README": "", "README.txt": "", "readme.md": ""},
+ "extensionless": {"Readme": ""},
+ "fallback": {
+ "README.md": {"file.md": ""},
+ "Readme.txt": ""
+ },
+ "invalid": {
+ "README.md": {"file.md": ""},
+ "README": {},
+ "README-extra.md": "",
+ "readme.template.md": "",
+ "rEaDmE.Md": "",
+ "README.adoc": "",
+ "prefix-readme.md": "",
+ "docs": {"README.md": ""}
+ },
+ "first": {"README.txt": ""},
+ "second": {"README.md": ""},
+ "parent": {"README.md": "", "src": {"README.md": ""}},
+ "local_settings": {
+ "README.md": "",
+ ".zed": {
+ "settings.json": r#"{"on_new_window": "readme"}"#
+ }
+ },
+ "none": {"code.rs": ""},
+ "explicit": {"README.md": "", "code.rs": ""},
+ "missing": {"README.md": ""}
+ }),
+ )
+ .await;
+
+ let readme = Some(settings::OnNewWindow::Readme);
+ for (on_new_window, paths, expected_path, preview) in [
+ (None, vec!["default"], None, false),
+ (
+ Some(settings::OnNewWindow::EmptyTab),
+ vec!["empty_tab"],
+ None,
+ false,
+ ),
+ (readme, vec!["markdown"], Some("markdown/readme.md"), true),
+ (
+ readme,
+ vec!["extensionless"],
+ Some("extensionless/Readme"),
+ true,
+ ),
+ (readme, vec!["fallback"], Some("fallback/Readme.txt"), true),
+ (readme, vec!["invalid"], None, false),
+ (
+ readme,
+ vec!["none", "first", "second"],
+ Some("first/README.txt"),
+ true,
+ ),
+ (
+ readme,
+ vec!["parent", "parent/src"],
+ Some("parent/README.md"),
+ true,
+ ),
+ (None, vec!["local_settings"], None, false),
+ (
+ readme,
+ vec!["explicit", "explicit/code.rs"],
+ Some("explicit/code.rs"),
+ false,
+ ),
+ (
+ readme,
+ vec!["missing/new.rs", "missing"],
+ Some("missing/new.rs"),
+ false,
+ ),
+ ] {
+ set_on_new_window(on_new_window, cx);
+ let paths = paths
+ .iter()
+ .map(|path| Path::new(path!("/root")).join(path))
+ .collect::<Vec<_>>();
+ let expected_paths = expected_path
+ .into_iter()
+ .map(|path| Path::new(path!("/root")).join(path))
+ .collect::<Vec<_>>();
+ let result = open_test_workspace_paths(paths, app_state.clone(), cx).await;
+ assert_workspace_item_paths(&result.workspace, &expected_paths, cx);
+ result.workspace.read_with(cx, |workspace, cx| {
+ let pane = workspace.active_pane().read(cx);
+ let expected_preview = if preview {
+ Some(pane.active_item().expect("README item").item_id())
+ } else {
+ None
+ };
+ assert_eq!(pane.preview_item_id(), expected_preview);
});
- });
+ result
+ .window
+ .update(cx, |_, window, _| window.remove_window())
+ .expect("close workspace");
+ cx.run_until_parked();
+ }
+ }
- cx.update(|cx| {
- open_new(
- Default::default(),
+ #[gpui::test]
+ async fn test_open_remote_project_readme(
+ cx: &mut TestAppContext,
+ server_cx: &mut TestAppContext,
+ ) {
+ let app_state = init_test(cx);
+ set_on_new_window(Some(settings::OnNewWindow::Readme), cx);
+ server_cx.update(|cx| {
+ release_channel::init(Version::new(0, 0, 0), cx);
+ HeadlessProject::init(cx);
+ });
+ let remote_fs = FakeFs::new(server_cx.executor());
+ for (name, explicit_file, expected_file) in [
+ ("directory", None, Some("README.md")),
+ ("explicit", Some("code.rs"), Some("code.rs")),
+ ("failed", Some(path!("/missing-parent/code.rs")), None),
+ ] {
+ let root = Path::new(path!("/root")).join(name);
+ remote_fs
+ .insert_tree(&root, json!({"README.md": "", "code.rs": ""}))
+ .await;
+ let (connection_options, server_session, connect_guard) =
+ RemoteClient::fake_server(cx, server_cx);
+ let languages = Arc::new(LanguageRegistry::new(server_cx.executor()));
+ let _headless = server_cx.new(|cx| {
+ HeadlessProject::new(
+ HeadlessAppState {
+ session: server_session,
+ fs: remote_fs.clone(),
+ http_client: Arc::new(BlockedHttpClient),
+ node_runtime: NodeRuntime::unavailable(),
+ languages,
+ extension_host_proxy: Arc::new(ExtensionHostProxy::new()),
+ startup_time: std::time::Instant::now(),
+ },
+ false,
+ cx,
+ )
+ });
+ drop(connect_guard);
+ let mut paths = vec![root.clone()];
+ if let Some(explicit_file) = explicit_file {
+ paths.push(root.join(explicit_file));
+ }
+ let window = open_remote_project(
+ connection_options,
+ paths,
app_state.clone(),
- cx,
- |workspace, window, cx| initialize_new_window(workspace, window, cx),
+ OpenOptions {
+ workspace_matching: workspace::WorkspaceMatching::None,
+ ..OpenOptions::default()
+ },
+ &mut cx.to_async(),
)
- })
- .await
- .unwrap();
- cx.run_until_parked();
+ .await
+ .expect("open remote project");
+ cx.run_until_parked();
+ let workspace = window
+ .read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone())
+ .expect("remote workspace");
+ let expected_paths = expected_file
+ .into_iter()
+ .map(|path| root.join(path))
+ .collect::<Vec<_>>();
+ assert_workspace_item_paths(&workspace, &expected_paths, cx);
+ window
+ .update(cx, |_, window, _| window.remove_window())
+ .expect("close remote workspace");
+ drop(workspace);
+ cx.run_until_parked();
+ }
+ }
- let multi_workspace = cx
- .update(|cx| cx.windows().first().unwrap().downcast::<MultiWorkspace>())
- .unwrap();
+ #[gpui::test]
+ async fn test_open_paths_readme_after_restoration(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ for restore_item in [false, true] {
+ set_on_new_window(Some(settings::OnNewWindow::Launchpad), cx);
+ let root = Path::new(path!("/root")).join(format!("restore-{restore_item}"));
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(&root, json!({"README.md": "", "code.rs": ""}))
+ .await;
+ let mut paths = vec![root.clone()];
+ if restore_item {
+ paths.push(root.join("code.rs"));
+ }
+ let result = open_test_workspace_paths(paths, app_state.clone(), cx).await;
+ let database_id = result
+ .workspace
+ .read_with(cx, |workspace, _| workspace.database_id())
+ .expect("persisted workspace id");
+ flush_workspace_serialization(&result.window, cx).await;
+ result
+ .window
+ .update(cx, |_, window, _| window.remove_window())
+ .expect("close workspace");
+ drop(result);
+ cx.run_until_parked();
- multi_workspace
- .update(cx, |multi_workspace, _, cx| {
- multi_workspace.workspace().update(cx, |workspace, cx| {
- assert!(
- workspace.active_item(cx).is_none(),
- "launchpad window should not open any items"
- );
- assert_eq!(
- workspace.active_pane().read(cx).items_len(),
- 0,
- "launchpad window should have an empty pane so the launchpad is shown"
- );
- });
+ set_on_new_window(Some(settings::OnNewWindow::Readme), cx);
+ let result = open_test_workspace_paths(vec![root.clone()], app_state.clone(), cx).await;
+ assert_eq!(
+ result
+ .workspace
+ .read_with(cx, |workspace, _| workspace.database_id()),
+ Some(database_id)
+ );
+ let expected_path = root.join(if restore_item { "code.rs" } else { "README.md" });
+ assert_workspace_item_paths(&result.workspace, &[expected_path], cx);
+ result
+ .window
+ .update(cx, |_, window, _| window.remove_window())
+ .expect("close workspace");
+ cx.run_until_parked();
+ }
+ }
+
+ #[gpui::test]
+ async fn test_add_folder_does_not_open_readme(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ set_on_new_window(Some(settings::OnNewWindow::Readme), cx);
+ app_state
+ .fs
+ .as_fake()
+ .insert_tree(
+ path!("/root"),
+ json!({
+ "existing": {"code.rs": ""},
+ "added": {"README.md": ""}
+ }),
+ )
+ .await;
+ let root = Path::new(path!("/root"));
+ let result =
+ open_test_workspace_paths(vec![root.join("existing")], app_state.clone(), cx).await;
+ assert_workspace_item_paths(&result.workspace, &[], cx);
+ result
+ .window
+ .update(cx, |_, window, cx| {
+ result.workspace.update(cx, |workspace, cx| {
+ workspace.open_paths(
+ vec![root.join("added")],
+ OpenOptions {
+ visible: Some(workspace::OpenVisible::All),
+ ..OpenOptions::default()
+ },
+ None,
+ window,
+ cx,
+ )
+ })
})
- .unwrap();
+ .expect("add folder")
+ .await;
+ cx.run_until_parked();
+ result.workspace.read_with(cx, |workspace, cx| {
+ assert_eq!(
+ workspace
+ .root_paths(cx)
+ .iter()
+ .map(|path| path.to_path_buf())
+ .collect::<Vec<_>>(),
+ vec![root.join("existing"), root.join("added")]
+ );
+ });
+ assert_workspace_item_paths(&result.workspace, &[], cx);
+ }
+
+ #[gpui::test]
+ async fn test_open_paths_readme_case_insensitive_fs(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ set_on_new_window(Some(settings::OnNewWindow::Readme), cx);
+ let fs = app_state.fs.as_fake();
+ fs.set_case_sensitive(false);
+ fs.insert_tree(path!("/root"), json!({"readme.md": ""}))
+ .await;
+ let result =
+ open_test_workspace_paths(vec![PathBuf::from(path!("/root"))], app_state.clone(), cx)
+ .await;
+ assert_workspace_item_paths(
+ &result.workspace,
+ &[PathBuf::from(path!("/root/readme.md"))],
+ cx,
+ );
}
#[gpui::test]
@@ -8307,6 +8613,55 @@ mod tests {
});
}
+ fn set_on_new_window(on_new_window: Option<settings::OnNewWindow>, cx: &mut TestAppContext) {
+ cx.update(|cx| {
+ SettingsStore::update_global(cx, |store, cx| {
+ store.update_user_settings(cx, |settings| {
+ settings.workspace.on_new_window = on_new_window;
+ });
+ });
+ });
+ }
+
+ async fn open_test_workspace_paths(
+ paths: Vec<PathBuf>,
+ app_state: Arc<AppState>,
+ cx: &mut TestAppContext,
+ ) -> workspace::OpenResult {
+ let result = cx
+ .update(|cx| {
+ open_paths(
+ &paths,
+ app_state,
+ OpenOptions {
+ workspace_matching: workspace::WorkspaceMatching::None,
+ ..OpenOptions::default()
+ },
+ cx,
+ )
+ })
+ .await
+ .expect("open workspace paths");
+ cx.run_until_parked();
+ result
+ }
+
+ fn assert_workspace_item_paths(
+ workspace: &Entity<Workspace>,
+ expected_paths: &[PathBuf],
+ cx: &TestAppContext,
+ ) {
+ workspace.read_with(cx, |workspace, cx| {
+ assert_eq!(workspace.open_item_abs_paths(cx), expected_paths);
+ assert_eq!(workspace.items(cx).count(), expected_paths.len());
+ let active_path = workspace
+ .active_item(cx)
+ .and_then(|item| item.project_path(cx))
+ .and_then(|path| workspace.project().read(cx).absolute_path(&path, cx));
+ assert_eq!(active_path.as_ref(), expected_paths.last());
+ });
+ }
+
fn has_view_item(cx: &mut App, item_name: &str) -> bool {
cx.get_menus()
.expect("reload_keymaps should populate the menu bar")
diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.md
index e206f51fc8c..0b80faf6036 100644
--- a/docs/src/reference/all-settings.md
+++ b/docs/src/reference/all-settings.md
@@ -3690,6 +3690,8 @@ If you wish to exclude certain hosts from using the proxy, set the `NO_PROXY` en
- Setting: `on_new_window`
- Default: `"launchpad"`
+In the Settings Editor, search for `On New Window` and choose an option.
+
**Options**
1. Show an empty untitled buffer:
@@ -3708,6 +3710,29 @@ If you wish to exclude certain hosts from using the proxy, set the `NO_PROXY` en
}
```
+3. Open a README when a new or reopened project has no open items:
+
+In the Settings Editor, set `On New Window` to `Readme`.
+
+Or add this to your settings.json:
+
+```json [settings]
+{
+ "on_new_window": "readme"
+}
+```
+
+Zed opens one README from the first project root with a match.
+Zed checks `README.md`, `readme.md`, `Readme.md`, `README`, `readme`, `Readme`, `README.txt`, `readme.txt`, and `Readme.txt`, in that order.
+These are direct root-level file checks, not a directory scan.
+Other spellings do not match, even on case-insensitive filesystems.
+File-index exclusions do not affect README discovery.
+Adding a folder to an already open project does not open a README.
+Files passed when opening the project and restored tabs take precedence.
+The README opens in a temporary [preview tab](#preview-tabs) when `preview_tabs.enabled` is `true`, or a regular tab otherwise.
+Zed uses your existing file opener settings, without forcing a rendered Markdown preview.
+If no matching README exists, Zed leaves the project's pane empty.
+
## Instrumentation
- Description: Configuration for developer-oriented instrumentation tools (profilers, tracers, etc.) that can be toggled at runtime.