ESC should exit both completion and insert mode

This commit is contained in:
Blaž Hrastnik 2021-05-29 10:37:47 +09:00
parent a28eaa81a0
commit d54ae09d3b
3 changed files with 25 additions and 13 deletions

View file

@ -207,6 +207,13 @@ impl Completion {
impl Component for Completion {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
// let the Editor handle Esc instead
if let Event::Key(KeyEvent {
code: KeyCode::Esc, ..
}) = event
{
return EventResult::Ignored;
}
self.popup.handle_event(event, cx)
}

View file

@ -584,7 +584,6 @@ impl Component for EditorView {
if completion.is_empty() {
self.completion = None;
}
// TODO: if exiting InsertMode, remove completion
}
}
}
@ -605,7 +604,9 @@ impl Component for EditorView {
let (view, doc) = cx.editor.current();
view.ensure_cursor_in_view(doc);
if mode == Mode::Normal && doc.mode() == Mode::Insert {
// mode transitions
match (mode, doc.mode()) {
(Mode::Normal, Mode::Insert) => {
// HAXX: if we just entered insert mode from normal, clear key buf
// and record the command that got us into this mode.
@ -614,7 +615,13 @@ impl Component for EditorView {
self.last_insert.0 = self.keymap[&mode][&key];
self.last_insert.1.clear();
};
}
(Mode::Insert, Mode::Normal) => {
// if exiting insert mode, remove completion
self.completion = None;
}
_ => (),
}
EventResult::Consumed(callback)
}

View file

@ -122,14 +122,12 @@ fn inner_rect(area: Rect) -> Rect {
let padding_vertical = area.height * 20 / 100;
let padding_horizontal = area.width * 20 / 100;
let area = Rect::new(
Rect::new(
area.x + padding_horizontal,
area.y + padding_vertical,
area.width - padding_horizontal * 2,
area.height - padding_vertical * 2,
);
area
)
}
impl<T: 'static> Component for Picker<T> {