Skip to content

Commit 038aaa1

Browse files
committed
move closing function out of consumed event result closure
1 parent e04c3a0 commit 038aaa1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

helix-term/src/ui/menu.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ impl<T: Item + 'static> Component for Menu<T> {
205205
_ => return EventResult::Ignored(None),
206206
};
207207

208-
let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor, _| {
208+
let close_fn = Some(Box::new(|compositor: &mut Compositor, _| {
209209
// remove the layer
210210
compositor.pop();
211-
})));
211+
}));
212212

213213
match event.into() {
214214
// esc or ctrl-c aborts the completion and closes the menu
215215
key!(Esc) | ctrl!('c') => {
216216
(self.callback_fn)(cx.editor, self.selection(), MenuEvent::Abort);
217-
return close_fn;
217+
return EventResult::Consumed(close_fn);
218218
}
219219
// arrow up/ctrl-p/shift-tab prev completion choice (including updating the doc)
220220
shift!(Tab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
@@ -231,13 +231,9 @@ impl<T: Item + 'static> Component for Menu<T> {
231231
key!(Enter) => {
232232
if let Some(selection) = self.selection() {
233233
(self.callback_fn)(cx.editor, Some(selection), MenuEvent::Validate);
234-
return close_fn;
234+
return EventResult::Consumed(close_fn);
235235
} else {
236-
return EventResult::Ignored(Some(Box::new(
237-
|compositor: &mut Compositor, _| {
238-
compositor.pop();
239-
},
240-
)));
236+
return EventResult::Ignored(close_fn);
241237
}
242238
}
243239
// KeyEvent {

0 commit comments

Comments
 (0)