Skip to content

Commit

Permalink
Clear resize info when closing all but one window (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa authored Aug 10, 2024
1 parent e6412d5 commit 51de3d1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/modalkit-ratatui/src/windows/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@ where
.collapse(target)
.and_then(AxisTree::singleton);
self._clamp_focus();
self.clear_sizes();

return self.root.size() == 0;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 51de3d1

Please sign in to comment.