Emit the WorktreeRemoved event when removing a worktree from a project

This commit is contained in:
Max Brunsfeld 2022-05-27 10:49:10 -07:00
parent a1a4c70845
commit e6be151a64

View file

@ -3603,11 +3603,19 @@ impl Project {
})
}
pub fn remove_worktree(&mut self, id: WorktreeId, cx: &mut ModelContext<Self>) {
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext<Self>) {
self.worktrees.retain(|worktree| {
worktree
.upgrade(cx)
.map_or(false, |w| w.read(cx).id() != id)
if let Some(worktree) = worktree.upgrade(cx) {
let id = worktree.read(cx).id();
if id == id_to_remove {
cx.emit(Event::WorktreeRemoved(id));
false
} else {
true
}
} else {
false
}
});
cx.notify();
}