Improve terminal.working_directory for non-project files (#18251)
This commit is contained in:
parent
27dfb48a7b
commit
eb4e7472e6
2 changed files with 12 additions and 8 deletions
|
@ -46,12 +46,16 @@ impl Project {
|
||||||
let worktree = self
|
let worktree = self
|
||||||
.active_entry()
|
.active_entry()
|
||||||
.and_then(|entry_id| self.worktree_for_entry(entry_id, cx))
|
.and_then(|entry_id| self.worktree_for_entry(entry_id, cx))
|
||||||
.or_else(|| self.worktrees(cx).next())?;
|
.into_iter()
|
||||||
let worktree = worktree.read(cx);
|
.chain(self.worktrees(cx))
|
||||||
if !worktree.root_entry()?.is_dir() {
|
.find_map(|tree| {
|
||||||
return None;
|
let worktree = tree.read(cx);
|
||||||
}
|
worktree
|
||||||
Some(worktree.abs_path().to_path_buf())
|
.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> {
|
pub fn first_project_directory(&self, cx: &AppContext) -> Option<PathBuf> {
|
||||||
|
|
|
@ -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]
|
#[gpui::test]
|
||||||
async fn active_entry_worktree_is_file(cx: &mut TestAppContext) {
|
async fn active_entry_worktree_is_file(cx: &mut TestAppContext) {
|
||||||
let (project, workspace) = init_test(cx).await;
|
let (project, workspace) = init_test(cx).await;
|
||||||
|
@ -1487,7 +1487,7 @@ mod tests {
|
||||||
assert!(active_entry.is_some());
|
assert!(active_entry.is_some());
|
||||||
|
|
||||||
let res = default_working_directory(workspace, cx);
|
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);
|
let res = first_project_directory(workspace, cx);
|
||||||
assert_eq!(res, Some((Path::new("/root1/")).to_path_buf()));
|
assert_eq!(res, Some((Path::new("/root1/")).to_path_buf()));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue