Skip to content

Commit

Permalink
handle menu navigation inapplicable on single item
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdillah committed Jul 20, 2023
1 parent 53b6a78 commit ee907e7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,41 +892,59 @@ 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)
})
}
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)
})
}
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)
})
}
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)
})
}
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)
})
}
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)
})
Expand Down

0 comments on commit ee907e7

Please sign in to comment.