1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-14 03:16:09 +03:00

advise the mux when a domain has detached; remove its tabs

This commit is contained in:
Wez Furlong 2019-06-25 08:59:19 -07:00
parent 5c6f44d47f
commit abfd98b7c6
3 changed files with 39 additions and 1 deletions

View File

@ -201,10 +201,16 @@ impl Mux {
pub fn remove_tab(&self, tab_id: TabId) {
debug!("removing tab {}", tab_id);
self.tabs.borrow_mut().remove(&tab_id);
self.prune_dead_windows();
}
pub fn prune_dead_windows(&self) {
let live_tab_ids: Vec<TabId> = self.tabs.borrow().keys().cloned().collect();
let mut windows = self.windows.borrow_mut();
let mut dead_windows = vec![];
for (window_id, win) in windows.iter_mut() {
if win.remove_by_id(tab_id) && win.is_empty() {
win.prune_dead_tabs(&live_tab_ids);
if win.is_empty() {
dead_windows.push(*window_id);
}
}
@ -273,6 +279,15 @@ impl Mux {
pub fn iter_domains(&self) -> Vec<Arc<dyn Domain>> {
self.domains.borrow().values().cloned().collect()
}
pub fn domain_was_detached(&self, domain: DomainId) {
self.tabs
.borrow_mut()
.retain(|_tab_id, tab| tab.domain_id() != domain);
// Ideally we'd do this here, but that seems to cause problems
// at the moment:
// self.prune_dead_windows();
}
}
#[derive(Debug, Fail)]

View File

@ -85,4 +85,25 @@ impl Window {
pub fn iter(&self) -> impl Iterator<Item = &Rc<dyn Tab>> {
self.tabs.iter()
}
pub fn prune_dead_tabs(&mut self, live_tab_ids: &[TabId]) {
let dead: Vec<TabId> = self
.tabs
.iter()
.filter_map(|tab| {
if live_tab_ids
.iter()
.find(|&&id| id == tab.tab_id())
.is_none()
{
Some(tab.tab_id())
} else {
None
}
})
.collect();
for tab_id in dead {
self.remove_by_id(tab_id);
}
}
}

View File

@ -99,6 +99,8 @@ impl ClientDomain {
pub fn perform_detach(&self) {
log::error!("detached domain {}", self.local_domain_id);
self.inner.borrow_mut().take();
let mux = Mux::get().unwrap();
mux.domain_was_detached(self.local_domain_id);
}
pub fn remote_to_local_tab_id(&self, remote_tab_id: TabId) -> Option<TabId> {