Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
terminal_view: Fix terminal opening in root directory when editing single file corktree (#42953)
Engin Açıkgözf17d2c92b6f8
diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex b9dabee7e82..66e6c605f9b 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -1556,7 +1556,8 @@ pub(crate) fn default_working_directory(workspace: &Workspace, cx: &App) -> Opti.read(cx).active_project_directory(cx).as_deref()- .map(Path::to_path_buf),+ .map(Path::to_path_buf)+ .or_else(|| first_project_directory(workspace, cx)),WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx),WorkingDirectory::AlwaysHome => None,WorkingDirectory::Always { directory } => {@@ -1570,10 +1571,13 @@ pub(crate) fn default_working_directory(workspace: &Workspace, cx: &App) -> Opti///Gets the first project's home directory, or the home directoryfn first_project_directory(workspace: &Workspace, cx: &App) -> Option<PathBuf> {let worktree = workspace.worktrees(cx).next()?.read(cx);- if !worktree.root_entry()?.is_dir() {- return None;+ let worktree_path = worktree.abs_path();+ if worktree.root_entry()?.is_dir() {+ Some(worktree_path.to_path_buf())+ } else {+ // If worktree is a file, return its parent directory+ worktree_path.parent().map(|p| p.to_path_buf())}- Some(worktree.abs_path().to_path_buf())}#[cfg(test)]@@ -1606,7 +1610,7 @@ mod tests {});}- // No active entry, but a worktree, worktree is a file -> home_dir()+ // No active entry, but a worktree, worktree is a file -> parent directory#[gpui::test]async fn no_active_entry_worktree_is_file(cx: &mut TestAppContext) {let (project, workspace) = init_test(cx).await;@@ -1621,9 +1625,9 @@ mod tests {assert!(workspace.worktrees(cx).next().is_some());let res = default_working_directory(workspace, cx);- assert_eq!(res, None);+ assert_eq!(res, Some(Path::new("/").to_path_buf()));let res = first_project_directory(workspace, cx);- assert_eq!(res, None);+ assert_eq!(res, Some(Path::new("/").to_path_buf()));});}