From 18434c0bf0526cb35715421e9a92631b900e2fa8 Mon Sep 17 00:00:00 2001 From: Hernawan Fa'iz Abdillah Date: Thu, 20 Jul 2023 14:03:31 +0700 Subject: [PATCH] handle menu navigation inapplicable on single item --- src/engine.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/engine.rs b/src/engine.rs index 8a70b7a3..794d40e9 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -980,6 +980,9 @@ impl Reedline { ReedlineEvent::MenuNext => { self.active_menu() .map_or(Ok(EventStatus::Inapplicable), |menu| { + if menu.get_values().len() < 2 { + return Ok(EventStatus::Inapplicable); + } menu.menu_event(MenuEvent::NextElement); Ok(EventStatus::Handled) }) @@ -987,6 +990,9 @@ impl Reedline { ReedlineEvent::MenuPrevious => { self.active_menu() .map_or(Ok(EventStatus::Inapplicable), |menu| { + if menu.get_values().len() < 2 { + return Ok(EventStatus::Inapplicable); + } menu.menu_event(MenuEvent::PreviousElement); Ok(EventStatus::Handled) }) @@ -994,6 +1000,9 @@ impl Reedline { ReedlineEvent::MenuUp => { self.active_menu() .map_or(Ok(EventStatus::Inapplicable), |menu| { + if menu.get_values().len() < 2 { + return Ok(EventStatus::Inapplicable); + } menu.menu_event(MenuEvent::MoveUp); Ok(EventStatus::Handled) }) @@ -1001,6 +1010,9 @@ impl Reedline { ReedlineEvent::MenuDown => { self.active_menu() .map_or(Ok(EventStatus::Inapplicable), |menu| { + if menu.get_values().len() < 2 { + return Ok(EventStatus::Inapplicable); + } menu.menu_event(MenuEvent::MoveDown); Ok(EventStatus::Handled) }) @@ -1008,6 +1020,9 @@ impl Reedline { ReedlineEvent::MenuLeft => { self.active_menu() .map_or(Ok(EventStatus::Inapplicable), |menu| { + if menu.get_values().len() < 2 { + return Ok(EventStatus::Inapplicable); + } menu.menu_event(MenuEvent::MoveLeft); Ok(EventStatus::Handled) }) @@ -1015,6 +1030,9 @@ impl Reedline { ReedlineEvent::MenuRight => { self.active_menu() .map_or(Ok(EventStatus::Inapplicable), |menu| { + if menu.get_values().len() < 2 { + return Ok(EventStatus::Inapplicable); + } menu.menu_event(MenuEvent::MoveRight); Ok(EventStatus::Handled) })