From be9b4cb36c9ae7349e31e4703065e76b231fc6b6 Mon Sep 17 00:00:00 2001 From: grovesNL Date: Thu, 26 Jan 2023 22:16:23 -0330 Subject: [PATCH] Avoid negative width/height in `Buffer::set_size` Negative width/height may cause unexpected effects on the layout, which we can avoid by clamping. --- src/buffer.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index da7e8ad..e12bca1 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -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(); }