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.
This commit is contained in:
Knoqx 2024-08-22 17:24:41 -04:00 committed by GitHub
parent e7c8dba54f
commit abc712014a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<ProjectEntryId>) {
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,