Skip to content

Commit

Permalink
move closing function out of consumed event result closure
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Feb 25, 2022
1 parent e04c3a0 commit 038aaa1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
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 = 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,13 +231,9 @@ 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 close_fn;
return EventResult::Consumed(close_fn);
} else {
return EventResult::Ignored(Some(Box::new(
|compositor: &mut Compositor, _| {
compositor.pop();
},
)));
return EventResult::Ignored(close_fn);
}
}
// KeyEvent {
Expand Down

0 comments on commit 038aaa1

Please sign in to comment.