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

ignore Enter keypress when menu has no selection #1704

Merged
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
12 changes: 7 additions & 5 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
compositor::{Component, Compositor, Context, EventResult},
compositor::{Callback, Component, Compositor, Context, EventResult},
ctrl, key, shift,
};
use crossterm::event::Event;
Expand Down Expand Up @@ -205,16 +205,16 @@ impl<T: Item + 'static> Component for Menu<T> {
_ => return EventResult::Ignored(None),
};

let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor, _| {
let close_fn: Option<Callback> = Some(Box::new(|compositor: &mut Compositor, _| {
// remove the layer
compositor.pop();
})));
}));

match event.into() {
// esc or ctrl-c aborts the completion and closes the menu
key!(Esc) | ctrl!('c') => {
(self.callback_fn)(cx.editor, self.selection(), MenuEvent::Abort);
return close_fn;
return EventResult::Consumed(close_fn);
}
// arrow up/ctrl-p/shift-tab prev completion choice (including updating the doc)
shift!(Tab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
Expand All @@ -231,8 +231,10 @@ impl<T: Item + 'static> Component for Menu<T> {
key!(Enter) => {
if let Some(selection) = self.selection() {
(self.callback_fn)(cx.editor, Some(selection), MenuEvent::Validate);
return EventResult::Consumed(close_fn);
} else {
return EventResult::Ignored(close_fn);
}
return close_fn;
}
// KeyEvent {
// code: KeyCode::Char(c),
Expand Down