diff --git a/src/dock_state/mod.rs b/src/dock_state/mod.rs index 34dc822..07e3888 100644 --- a/src/dock_state/mod.rs +++ b/src/dock_state/mod.rs @@ -297,7 +297,11 @@ impl DockState { &mut self, (surface_index, node_index, tab_index): (SurfaceIndex, NodeIndex, TabIndex), ) -> Option { - self[surface_index].remove_tab((node_index, tab_index)) + let removed_tab = self[surface_index].remove_tab((node_index, tab_index)); + if !surface_index.is_main() && self[surface_index].is_empty() { + self.remove_surface(surface_index); + } + removed_tab } /// Creates two new nodes by splitting a given `parent` node and assigns them as its children. The first (old) node diff --git a/src/dock_state/tree/mod.rs b/src/dock_state/tree/mod.rs index 1ff22ce..4c8d598 100644 --- a/src/dock_state/tree/mod.rs +++ b/src/dock_state/tree/mod.rs @@ -580,8 +580,10 @@ impl Tree { /// /// # Panics /// - /// If the node at index `node` is not a [`Leaf`](Node::Leaf). + /// - If the tree is empty. + /// - If the node at index `node` is not a [`Leaf`](Node::Leaf). pub fn remove_leaf(&mut self, node: NodeIndex) { + assert!(!self.is_empty()); assert!(self[node].is_leaf()); let Some(parent) = node.parent() else {