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.

Improve terminal.working_directory for non-project files (#18251)

Peter Trippeb4e7472e69f
diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs
index 0ccf730d9ef..45b79a7a5c9 100644
--- a/crates/project/src/terminals.rs
+++ b/crates/project/src/terminals.rs
@@ -46,12 +46,16 @@ impl Project {
let worktree = self
.active_entry()
.and_then(|entry_id| self.worktree_for_entry(entry_id, cx))
- .or_else(|| self.worktrees(cx).next())?;
- let worktree = worktree.read(cx);
- if !worktree.root_entry()?.is_dir() {
- return None;
- }
- Some(worktree.abs_path().to_path_buf())
+ .into_iter()
+ .chain(self.worktrees(cx))
+ .find_map(|tree| {
+ let worktree = tree.read(cx);
+ worktree
+ .root_entry()
+ .filter(|entry| entry.is_dir())
+ .map(|_| worktree.abs_path().to_path_buf())
+ });
+ worktree
}
pub fn first_project_directory(&self, cx: &AppContext) -> Option<PathBuf> {
diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs
index de501ab80a5..6a23e45f549 100644
--- a/crates/terminal_view/src/terminal_view.rs
+++ b/crates/terminal_view/src/terminal_view.rs
@@ -1471,7 +1471,7 @@ mod tests {
});
}
- // Active entry with a work tree, worktree is a file -> home_dir()
+ // Active entry with a work tree, worktree is a file -> worktree_folder()
#[gpui::test]
async fn active_entry_worktree_is_file(cx: &mut TestAppContext) {
let (project, workspace) = init_test(cx).await;
@@ -1487,7 +1487,7 @@ mod tests {
assert!(active_entry.is_some());
let res = default_working_directory(workspace, cx);
- assert_eq!(res, None);
+ assert_eq!(res, Some((Path::new("/root1/")).to_path_buf()));
let res = first_project_directory(workspace, cx);
assert_eq!(res, Some((Path::new("/root1/")).to_path_buf()));
});