From 4a2ad21247becb6333e9e85b292e72a6fcbdc9a4 Mon Sep 17 00:00:00 2001 From: Stephen Broadley Date: Sun, 4 Aug 2024 21:35:45 +0100 Subject: [PATCH] ensure we don't form invalid Rects with 'split_***' API --- helix-view/src/graphics.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/helix-view/src/graphics.rs b/helix-view/src/graphics.rs index c5b6f9baf..bd9bd21a3 100644 --- a/helix-view/src/graphics.rs +++ b/helix-view/src/graphics.rs @@ -256,6 +256,7 @@ impl Rect { } pub fn split_left(self, width: u16) -> (Rect, Rect) { + let width = width.min(self.width); ( Rect { width, ..self }, Rect { @@ -267,6 +268,7 @@ impl Rect { } pub fn split_right(self, width: u16) -> (Rect, Rect) { + let width = width.min(self.width); ( Rect { width: self.width - width, @@ -281,6 +283,7 @@ impl Rect { } pub fn split_top(self, height: u16) -> (Rect, Rect) { + let height = height.min(self.height); ( Rect { height, ..self }, Rect { @@ -292,6 +295,7 @@ impl Rect { } pub fn split_bottom(self, height: u16) -> (Rect, Rect) { + let height = height.min(self.height); ( Rect { height: self.height - height, @@ -306,6 +310,7 @@ impl Rect { } pub fn split_centre_vertical(self, width: u16) -> (Rect, Rect, Rect) { + let width = width.min(self.width); let l = (self.width - width) / 2; let r = self.width - width - l; (