Fix Recent Documents List (continues #8952) (#9919)

@SomeoneToIgnore This code should 100% work for future Zed users, but
for current Zed users, Zed's internal list of recents may not be synced
w/ macOS' Recent Documents at first. If needed this can be fixed by
calling `cx.refresh_recent_documents` on startup, but that feels a bit
unnecessary.

Release Notes:

- Fixes behavior of Recent Documents list on macOS
This commit is contained in:
Daniel Zhu 2024-03-29 14:17:25 -07:00 committed by GitHub
parent 35e1229fbb
commit 30193647f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 17 additions and 89 deletions

View file

@ -607,16 +607,7 @@ impl Workspace {
project::Event::WorktreeRemoved(_) | project::Event::WorktreeAdded => {
this.update_window_title(cx);
let workspace_serialization = this.serialize_workspace(cx);
cx.spawn(|workspace, mut cx| async move {
workspace_serialization.await;
workspace
.update(&mut cx, |workspace, cx| {
workspace.refresh_recent_documents(cx)
})?
.await
})
.detach_and_log_err(cx)
this.serialize_workspace(cx).detach();
}
project::Event::DisconnectedFromHost => {
@ -946,12 +937,7 @@ impl Workspace {
.unwrap_or_default();
window
.update(&mut cx, |workspace, cx| {
workspace
.refresh_recent_documents(cx)
.detach_and_log_err(cx);
cx.activate_window()
})
.update(&mut cx, |_, cx| cx.activate_window())
.log_err();
Ok((window, opened_items))
})
@ -3491,33 +3477,6 @@ impl Workspace {
Task::ready(())
}
fn refresh_recent_documents(&self, cx: &mut AppContext) -> Task<Result<()>> {
if !self.project.read(cx).is_local() {
return Task::ready(Ok(()));
}
cx.spawn(|cx| async move {
let recents = WORKSPACE_DB
.recent_workspaces_on_disk()
.await
.unwrap_or_default();
let mut unique_paths = HashMap::default();
for (id, workspace) in &recents {
for path in workspace.paths().iter() {
unique_paths.insert(path.clone(), id);
}
}
let current_paths = unique_paths
.into_iter()
.sorted_by_key(|(_, id)| *id)
.map(|(path, _)| path)
.collect::<Vec<_>>();
cx.update(|cx| {
cx.clear_recent_documents();
cx.add_recent_documents(&current_paths);
})
})
}
pub(crate) fn load_workspace(
serialized_workspace: SerializedWorkspace,
paths_to_open: Vec<Option<ProjectPath>>,