Merge pull request #66 from grovesNL/clamp-size

Avoid negative width/height in `Buffer::set_size`
This commit is contained in:
Jeremy Soller 2023-01-26 20:18:22 -07:00 committed by GitHub
commit 983d6b7eac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -516,9 +516,12 @@ impl<'a> Buffer<'a> {
/// Set the current buffer dimensions
pub fn set_size(&mut self, width: i32, height: i32) {
if width != self.width || height != self.height {
self.width = width;
self.height = height;
let clamped_width = width.max(0);
let clamped_height = height.max(0);
if clamped_width != self.width || clamped_height != self.height {
self.width = clamped_width;
self.height = clamped_height;
self.relayout();
self.shape_until_scroll();
}