@@ -101,11 +101,11 @@ fn toggle_file_finder(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContex
});
// if exists, bubble the currently opened path to the top
- let history_items = dbg!(dbg!(currently_opened_path.clone())
+ let history_items = currently_opened_path
+ .clone()
.into_iter()
.chain(
workspace
- // TODO kb history contains empty paths
.recent_navigation_history(Some(MAX_RECENT_SELECTIONS), cx)
.into_iter()
.filter(|(history_path, _)| {
@@ -116,7 +116,7 @@ fn toggle_file_finder(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContex
})
.map(|(history_path, abs_path)| FoundPath::new(history_path, abs_path)),
)
- .collect());
+ .collect();
let project = workspace.project().clone();
let workspace = cx.handle().downgrade();
@@ -492,7 +492,7 @@ impl Pane {
if let Some((project_path, entry)) = to_load {
// If the item was no longer present, then load it again from its previous path.
- let task = workspace.load_path(project_path.clone(), cx);
+ let task = workspace.load_path(project_path, cx);
cx.spawn(|workspace, mut cx| async move {
let task = task.await;
let mut navigated = false;
@@ -510,7 +510,6 @@ impl Pane {
workspace,
pane.clone(),
project_entry_id,
- &project_path,
true,
cx,
build_item,
@@ -547,7 +546,6 @@ impl Pane {
workspace: &mut Workspace,
pane: ViewHandle<Pane>,
project_entry_id: ProjectEntryId,
- project_path: &ProjectPath,
focus_item: bool,
cx: &mut ViewContext<Workspace>,
build_item: impl FnOnce(&mut ViewContext<Pane>) -> Box<dyn ItemHandle>,
@@ -580,15 +578,6 @@ impl Pane {
None,
cx,
);
- {
- let abs_path = workspace.absolute_path(project_path, cx);
- pane.read(cx)
- .nav_history
- .borrow_mut()
- .paths_by_item
- .insert(new_item.id(), (project_path.clone(), abs_path));
- }
-
new_item
}
}
@@ -602,6 +591,20 @@ impl Pane {
destination_index: Option<usize>,
cx: &mut ViewContext<Workspace>,
) {
+ if item.is_singleton(cx) {
+ if let Some(&entry_id) = item.project_entry_ids(cx).get(0) {
+ if let Some(project_path) =
+ workspace.project().read(cx).path_for_entry(entry_id, cx)
+ {
+ let abs_path = workspace.absolute_path(&project_path, cx);
+ pane.read(cx)
+ .nav_history
+ .borrow_mut()
+ .paths_by_item
+ .insert(item.id(), (project_path, abs_path));
+ }
+ }
+ }
// If no destination index is specified, add or move the item after the active item.
let mut insertion_index = {
let pane = pane.read(cx);
@@ -1984,7 +1987,6 @@ impl PaneNavHistory {
f(entry, project_and_abs_path.clone());
} else if let Some(item) = entry.item.upgrade(cx) {
if let Some(path) = item.project_path(cx) {
- // TODO kb ??? this should be the full path
f(entry, (path, None));
}
}
@@ -1306,14 +1306,19 @@ impl Workspace {
}
pub fn absolute_path(&self, project_path: &ProjectPath, cx: &AppContext) -> Option<PathBuf> {
- Some(
- self.project()
- .read(cx)
- .worktree_for_id(project_path.worktree_id, cx)?
- .read(cx)
- .abs_path()
- .to_path_buf(),
- )
+ let workspace_root = self
+ .project()
+ .read(cx)
+ .worktree_for_id(project_path.worktree_id, cx)?
+ .read(cx)
+ .abs_path();
+ let project_path = project_path.path.as_ref();
+
+ Some(if project_path == Path::new("") {
+ workspace_root.to_path_buf()
+ } else {
+ workspace_root.join(project_path)
+ })
}
fn add_folder_to_project(&mut self, _: &AddFolderToProject, cx: &mut ViewContext<Self>) {
@@ -1661,23 +1666,14 @@ impl Workspace {
})
});
- let project_path = path.into();
- let task = self.load_path(project_path.clone(), cx);
+ let task = self.load_path(path.into(), cx);
cx.spawn(|this, mut cx| async move {
let (project_entry_id, build_item) = task.await?;
let pane = pane
.upgrade(&cx)
.ok_or_else(|| anyhow!("pane was closed"))?;
this.update(&mut cx, |this, cx| {
- Pane::open_item(
- this,
- pane,
- project_entry_id,
- &project_path,
- focus_item,
- cx,
- build_item,
- )
+ Pane::open_item(this, pane, project_entry_id, focus_item, cx, build_item)
})
})
}