From abc712014ab76e5e0b8497fb221c5dcd72c837df Mon Sep 17 00:00:00 2001 From: Knoqx <43473765+Quplet@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:24:41 -0400 Subject: [PATCH] Recursive tab/pane closing on folder deletion (#15222) Release Notes: - Added tab/pane closing for files inside a folder being deleted/trashed Behavior prior: [Screencast from 2024-07-25 16-26-47.webm](https://github.com/user-attachments/assets/b090f582-bd7e-411d-91b9-d6709aca7295) New behavior: [Screencast from 2024-07-25 16-27-53.webm](https://github.com/user-attachments/assets/b35d4c3a-b0ab-4bd3-bcee-e8b6ad1419c3) This is primarily a proof of concept PR as I'm sure there are more elegant ways of achieving this. It's been bothering me for a little while manually closing file tabs in a folder I deleted, and since this is standard behavior on almost all IDEs and text editors I figured it would be a nice small little challenge. If there are any changes y'all want made I'd be happy to. --- crates/worktree/src/worktree.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 0461db4bf7..5485acb008 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -743,10 +743,31 @@ impl Worktree { Worktree::Local(this) => this.delete_entry(entry_id, trash, cx), Worktree::Remote(this) => this.delete_entry(entry_id, trash, cx), }?; - cx.emit(Event::DeletedEntry(entry_id)); + + let entry = match self { + Worktree::Local(ref this) => this.entry_for_id(entry_id), + Worktree::Remote(ref this) => this.entry_for_id(entry_id), + }?; + + let mut ids = vec![entry_id]; + let path = &*entry.path; + + self.get_children_ids_recursive(path, &mut ids); + + for id in ids { + cx.emit(Event::DeletedEntry(id)); + } Some(task) } + fn get_children_ids_recursive(&self, path: &Path, ids: &mut Vec) { + let children_iter = self.child_entries(path); + for child in children_iter { + ids.push(child.id); + self.get_children_ids_recursive(&child.path, ids); + } + } + pub fn rename_entry( &mut self, entry_id: ProjectEntryId,