Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inapplicable condition on menu activation and navigation #608

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle menu navigation inapplicable on single item
Abdillah committed Oct 21, 2023
commit 18434c0bf0526cb35715421e9a92631b900e2fa8
18 changes: 18 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
@@ -980,41 +980,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)
})