Prompt needs to close on enter.

pull/7/head
Blaž Hrastnik 4 years ago
parent ca809617b2
commit f92998a14b

@ -151,6 +151,11 @@ impl Component for Prompt {
_ => return EventResult::Ignored, _ => return EventResult::Ignored,
}; };
let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
// remove the layer
compositor.pop();
})));
match event { match event {
KeyEvent { KeyEvent {
code: KeyCode::Char(c), code: KeyCode::Char(c),
@ -159,10 +164,7 @@ impl Component for Prompt {
KeyEvent { KeyEvent {
code: KeyCode::Esc, .. code: KeyCode::Esc, ..
} => { } => {
return EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { return close_fn;
// remove the layer
compositor.pop();
})));
} }
KeyEvent { KeyEvent {
code: KeyCode::Right, code: KeyCode::Right,
@ -187,7 +189,10 @@ impl Component for Prompt {
KeyEvent { KeyEvent {
code: KeyCode::Enter, code: KeyCode::Enter,
.. ..
} => (self.callback_fn)(cx.editor, &self.line), } => {
(self.callback_fn)(cx.editor, &self.line);
return close_fn;
}
KeyEvent { KeyEvent {
code: KeyCode::Tab, .. code: KeyCode::Tab, ..
} => self.change_completion_selection(), } => self.change_completion_selection(),

Loading…
Cancel
Save