on master help sign in
ESC should exit both completion and insert mode
commitd54ae09d3b7a5eb56050631a58e75a1d1686ea70 authorBlaž Hrastnik <blaz@mxxn.io> dateSat 29 May 2021, 10:37 (5 years ago) parenta28eaa8
3 files changed+25−13
helix-term/src/ui/completion.rs+7 helix-term/src/ui/editor.rs+16−9 helix-term/src/ui/picker.rs+2−4
helix-term/src/ui/completion.rs+7
@@ -207,6 +207,13 @@ impl Completion {
207207
208208impl Component for Completion {
209209 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
210+ // let the Editor handle Esc instead
211+ if let Event::Key(KeyEvent {
212+ code: KeyCode::Esc, ..
213+ }) = event
214+ {
215+ return EventResult::Ignored;
216+ }
210217 self.popup.handle_event(event, cx)
211218 }
212219
helix-term/src/ui/editor.rs+16−9
@@ -584,7 +584,6 @@ impl Component for EditorView {
584584 if completion.is_empty() {
585585 self.completion = None;
586586 }
587− // TODO: if exiting InsertMode, remove completion
588587 }
589588 }
590589 }
@@ -605,16 +604,24 @@ impl Component for EditorView {
605604 let (view, doc) = cx.editor.current();
606605 view.ensure_cursor_in_view(doc);
607606
608− if mode == Mode::Normal && doc.mode() == Mode::Insert {
609− // HAXX: if we just entered insert mode from normal, clear key buf
610− // and record the command that got us into this mode.
607+ // mode transitions
608+ match (mode, doc.mode()) {
609+ (Mode::Normal, Mode::Insert) => {
610+ // HAXX: if we just entered insert mode from normal, clear key buf
611+ // and record the command that got us into this mode.
611612
612− // how we entered insert mode is important, and we should track that so
613− // we can repeat the side effect.
613+ // how we entered insert mode is important, and we should track that so
614+ // we can repeat the side effect.
614615
615− self.last_insert.0 = self.keymap[&mode][&key];
616− self.last_insert.1.clear();
617− };
616+ self.last_insert.0 = self.keymap[&mode][&key];
617+ self.last_insert.1.clear();
618+ }
619+ (Mode::Insert, Mode::Normal) => {
620+ // if exiting insert mode, remove completion
621+ self.completion = None;
622+ }
623+ _ => (),
624+ }
618625
619626 EventResult::Consumed(callback)
620627 }
helix-term/src/ui/picker.rs+2−4
@@ -122,14 +122,12 @@ fn inner_rect(area: Rect) -> Rect {
122122 let padding_vertical = area.height * 20 / 100;
123123 let padding_horizontal = area.width * 20 / 100;
124124
125− let area = Rect::new(
125+ Rect::new(
126126 area.x + padding_horizontal,
127127 area.y + padding_vertical,
128128 area.width - padding_horizontal * 2,
129129 area.height - padding_vertical * 2,
130− );
131−
132− area
130+ )
133131}
134132
135133impl<T: 'static> Component for Picker<T> {