From fe88657ea1a2c7b60b0eeb06c7a8cac1ce11f95d Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 27 Aug 2024 16:28:53 -0400 Subject: [PATCH] Early return from MenuPopup::scroll_{up,down} when the menu is empty --- cursive-core/src/views/menu_popup.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cursive-core/src/views/menu_popup.rs b/cursive-core/src/views/menu_popup.rs index b23ebc67..84dccba1 100644 --- a/cursive-core/src/views/menu_popup.rs +++ b/cursive-core/src/views/menu_popup.rs @@ -131,6 +131,10 @@ impl MenuPopup { // // If `self.menu.children.is_empty()`. fn scroll_up(&mut self, mut n: usize, mut cycle: bool) { + if self.menu.is_empty() { + return; + } + while n > 0 { if self.focus > 0 { self.focus -= 1; @@ -154,6 +158,10 @@ impl MenuPopup { // // If `self.menu.children.is_empty()`. fn scroll_down(&mut self, mut n: usize, mut cycle: bool) { + if self.menu.is_empty() { + return; + } + while n > 0 { if self.focus + 1 < self.menu.children.len() { self.focus += 1;