From b535ff9e5872b5523a37cce9c1c62d648ea3ad35 Mon Sep 17 00:00:00 2001 From: Hernawan Fa'iz Abdillah Date: Thu, 20 Jul 2023 14:03:07 +0700 Subject: [PATCH 1/4] handle empty menu as inapplicable --- src/engine.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine.rs b/src/engine.rs index c87afac8..8a70b7a3 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -967,6 +967,11 @@ impl Reedline { return Ok(EventStatus::Handled); } + if menu.get_values().len() == 0 { + menu.menu_event(MenuEvent::Deactivate); + return Ok(EventStatus::Inapplicable); + } + return Ok(EventStatus::Handled); } } 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 2/4] 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) }) From c3679bb8e92c0ca2a6594ae2e42aae0cb3238314 Mon Sep 17 00:00:00 2001 From: Hernawan Fa'iz Abdillah Date: Fri, 21 Jul 2023 09:50:50 +0700 Subject: [PATCH 3/4] fix use is_empty rather check len --- src/engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index 794d40e9..6e0b6c33 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -967,7 +967,7 @@ impl Reedline { return Ok(EventStatus::Handled); } - if menu.get_values().len() == 0 { + if menu.get_values().is_empty() { menu.menu_event(MenuEvent::Deactivate); return Ok(EventStatus::Inapplicable); } From 0c27b0a1ce4111180d5be6036921489ff1bc739e Mon Sep 17 00:00:00 2001 From: Hernawan Fa'iz Abdillah Date: Sat, 22 Jul 2023 06:51:09 +0700 Subject: [PATCH 4/4] make menu inapplicable only for quick completion --- src/engine.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index 6e0b6c33..fdddc895 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -967,7 +967,10 @@ impl Reedline { return Ok(EventStatus::Handled); } - if menu.get_values().is_empty() { + if self.quick_completions + && menu.can_quick_complete() + && menu.get_values().is_empty() + { menu.menu_event(MenuEvent::Deactivate); return Ok(EventStatus::Inapplicable); }