From 51de3d1a82138400731f487f048f11d54ec34dea Mon Sep 17 00:00:00 2001 From: Ulyssa Date: Fri, 9 Aug 2024 22:42:44 -0700 Subject: [PATCH] Clear resize info when closing all but one window (#147) --- crates/modalkit-ratatui/src/windows/layout.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/modalkit-ratatui/src/windows/layout.rs b/crates/modalkit-ratatui/src/windows/layout.rs index db628b7..97e377c 100644 --- a/crates/modalkit-ratatui/src/windows/layout.rs +++ b/crates/modalkit-ratatui/src/windows/layout.rs @@ -1429,6 +1429,7 @@ where .collapse(target) .and_then(AxisTree::singleton); self._clamp_focus(); + self.clear_sizes(); return self.root.size() == 0; } @@ -2550,6 +2551,32 @@ mod tests { } } + #[test] + fn test_window_close_allbut_resize_lens() { + let (mut tree, mut store, ctx) = mktree(); + window_split!(tree, Axis::Horizontal, MoveDir1D::Previous, Count::Exact(1), &ctx, store); + let mut buffer = Buffer::empty(Rect::new(0, 0, 100, 100)); + let area = Rect::new(0, 0, 100, 100); + let idx = 1; + + // Draw so that everything gets an initial area. + WindowLayout::new(&mut store).render(area, &mut buffer, &mut tree); + + // Resize the tree so we have lengths in ResizeInfo. + tree.resize(idx, Axis::Horizontal, SizeChange::Increase(10)); + assert!(tree.info.resized.lengths.is_some()); + + // Now close, which should reset the ResizeInfo. + let target = WindowTarget::AllBut(fc!(idx + 1)); + assert!(window_close!(tree, target, CloseFlags::NONE, &ctx, store).is_none()); + assert!(tree.info.resized.lengths.is_none()); + assert_eq!(tree.root.size(), 1); + assert_eq!(tree.focused, 0); + + // Now draw again, which shouldn't trip our assertions. + WindowLayout::new(&mut store).render(area, &mut buffer, &mut tree); + } + #[test] fn test_window_close_all() { let (mut tree, mut store, ctx) = three_by_three();