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

Moved partial completion menu next into new menu event #881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 24 additions & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ impl Reedline {
| ReedlineEvent::OpenEditor
| ReedlineEvent::Menu(_)
| ReedlineEvent::MenuNext
| ReedlineEvent::MenuNextComplete
| ReedlineEvent::MenuPrevious
| ReedlineEvent::MenuUp
| ReedlineEvent::MenuDown
Expand Down Expand Up @@ -968,13 +969,33 @@ impl Reedline {
Ok(EventStatus::Inapplicable)
}
ReedlineEvent::MenuNext => {
if let Some(menu) = self.active_menu() {
if menu.get_values().len() == 1 && menu.can_quick_complete() {
self.handle_editor_event(prompt, ReedlineEvent::Enter)
} else {
menu.menu_event(MenuEvent::NextElement);
Ok(EventStatus::Handled)
}
} else {
Ok(EventStatus::Inapplicable)
}
}
ReedlineEvent::MenuNextComplete => {
// Ensure values are updated before this event is called!
if let Some(menu) = self.menus.iter_mut().find(|menu| menu.is_active()) {
if menu.get_values().len() == 1 && menu.can_quick_complete() {
self.handle_editor_event(prompt, ReedlineEvent::Enter)
} else {
if self.partial_completions {
menu.can_partially_complete(
self.quick_completions,
// Requires can partially complete to actually also complete.
if self.partial_completions
&& menu.can_partially_complete(
true,
&mut self.editor,
self.completer.as_mut(),
self.history.as_ref(),
)
{
menu.update_values(
&mut self.editor,
self.completer.as_mut(),
self.history.as_ref(),
Expand Down
4 changes: 4 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ pub enum ReedlineEvent {
/// Next element in the menu
MenuNext,

/// Next element in menu with partial completions
MenuNextComplete,

/// Previous element in the menu
MenuPrevious,

Expand Down Expand Up @@ -678,6 +681,7 @@ impl Display for ReedlineEvent {
ReedlineEvent::UntilFound(_) => write!(f, "UntilFound [ {{ ReedLineEvents, }} ]"),
ReedlineEvent::Menu(_) => write!(f, "Menu Name: <string>"),
ReedlineEvent::MenuNext => write!(f, "MenuNext"),
ReedlineEvent::MenuNextComplete => write!(f, "MenuNextComplete"),
ReedlineEvent::MenuPrevious => write!(f, "MenuPrevious"),
ReedlineEvent::MenuUp => write!(f, "MenuUp"),
ReedlineEvent::MenuDown => write!(f, "MenuDown"),
Expand Down