From 6eccd6d2d7ecec79c006d9e5d95f57746b898dd3 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 27 Sep 2020 14:07:56 -0700 Subject: [PATCH] wezterm: un-zoom while calculating pane sizes in resize --- src/mux/tab.rs | 64 +++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/mux/tab.rs b/src/mux/tab.rs index 5165eafde..681461038 100644 --- a/src/mux/tab.rs +++ b/src/mux/tab.rs @@ -575,43 +575,49 @@ impl Tab { /// Apply the new size of the tab to the panes contained within. /// This works by adjusting the size of the second half of each split. pub fn resize(&self, size: PtySize) { - let mut root = self.pane.borrow_mut(); + // Un-zoom first, so that the layout can be reasoned about + // more easily. + let was_zoomed = self.zoomed.borrow().is_some(); + self.set_zoomed(false); - *self.size.borrow_mut() = size; - if let Some(zoomed) = self.zoomed.borrow().as_ref() { - zoomed.resize(size).ok(); - return; - } + { + let mut root = self.pane.borrow_mut(); - let mut cursor = root.take().unwrap().cursor(); + *self.size.borrow_mut() = size; - loop { - // Figure out the available size by looking at our immediate parent node. - // If we are the root, look at the provided new size - let pane_size = if let Some((branch, Some(parent))) = cursor.path_to_root().next() { - if branch == PathBranch::IsRight { - parent.second + let mut cursor = root.take().unwrap().cursor(); + + loop { + // Figure out the available size by looking at our immediate parent node. + // If we are the root, look at the provided new size + let pane_size = if let Some((branch, Some(parent))) = cursor.path_to_root().next() { + if branch == PathBranch::IsRight { + parent.second + } else { + parent.first + } } else { - parent.first - } - } else { - size - }; + size + }; - if cursor.is_leaf() { - // Apply our size to the tty - cursor.leaf_mut().map(|pane| pane.resize(pane_size)); - } else { - self.apply_pane_size(pane_size, &mut cursor); - } - match cursor.preorder_next() { - Ok(c) => cursor = c, - Err(c) => { - root.replace(c.tree()); - break; + if cursor.is_leaf() { + // Apply our size to the tty + cursor.leaf_mut().map(|pane| pane.resize(pane_size)); + } else { + self.apply_pane_size(pane_size, &mut cursor); + } + match cursor.preorder_next() { + Ok(c) => cursor = c, + Err(c) => { + root.replace(c.tree()); + break; + } } } } + + // And finally restore the zoom, if appropriate + self.set_zoomed(was_zoomed); } fn apply_pane_size(&self, pane_size: PtySize, cursor: &mut Cursor) {