Close Servo live sessions for removed tabs

This commit is contained in:
2026-05-13 02:41:54 -04:00
parent 74731d4faa
commit ac84a80d9e
11 changed files with 133 additions and 5 deletions
+24
View File
@@ -97,6 +97,22 @@ impl WebSurfaceStore {
result
}
pub(super) fn retain_tabs(&mut self, open_tab_ids: &[TabId]) {
let stale_tab_ids = self
.surfaces
.keys()
.filter(|tab_id| !open_tab_ids.iter().any(|open_tab_id| open_tab_id == *tab_id))
.cloned()
.collect::<Vec<_>>();
for tab_id in stale_tab_ids {
self.close_surface(&tab_id);
}
}
pub(super) fn close_surface(&mut self, tab_id: &TabId) {
self.close_surface_for_tab(tab_id);
}
pub(super) fn record_scroll_delta(
&mut self,
tab_id: &TabId,
@@ -334,6 +350,14 @@ impl WebSurfaceStore {
self.surfaces.entry(tab_id.clone()).or_insert_with(PerTabSurface::new)
}
fn close_surface_for_tab(&mut self, tab_id: &TabId) {
self.runtime.close_tab(tab_id);
self.surfaces.remove(tab_id);
if self.keyboard_focus.as_ref().is_some_and(|focus| focus.tab_id == *tab_id) {
self.keyboard_focus = None;
}
}
#[cfg(test)]
pub(super) fn surface_for_test(&self, tab_id: &TabId) -> Option<&PerTabSurface> {
self.surfaces.get(tab_id)