Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear resize info when closing all but one window #147

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading