on master help sign in
ESC should exit both completion and insert mode
d54ae09Blaž Hrastnik
helix-term/src/ui/completion.rs+7
@@ -207,6 +207,13 @@ impl Completion {
207
207
208impl Component for Completion {
208impl Component for Completion {
209 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
209 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+ }
210 self.popup.handle_event(event, cx)
217 self.popup.handle_event(event, cx)
211 }
218 }
212
219
helix-term/src/ui/editor.rs+16−9
@@ -584,7 +584,6 @@ impl Component for EditorView {
584 if completion.is_empty() {
584 if completion.is_empty() {
585 self.completion = None;
585 self.completion = None;
586 }
586 }
587− // TODO: if exiting InsertMode, remove completion
588 }
587 }
589 }
588 }
590 }
589 }
@@ -605,16 +604,24 @@ impl Component for EditorView {
605 let (view, doc) = cx.editor.current();
604 let (view, doc) = cx.editor.current();
606 view.ensure_cursor_in_view(doc);
605 view.ensure_cursor_in_view(doc);
607
606
608− if mode == Mode::Normal && doc.mode() == Mode::Insert {
607+ // mode transitions
608+ match (mode, doc.mode()) {
609+ (Mode::Normal, Mode::Insert) => {
609− // HAXX: if we just entered insert mode from normal, clear key buf
610+ // HAXX: if we just entered insert mode from normal, clear key buf
610− // and record the command that got us into this mode.
611+ // and record the command that got us into this mode.
611
612
612− // how we entered insert mode is important, and we should track that so
613+ // how we entered insert mode is important, and we should track that so
613− // we can repeat the side effect.
614+ // we can repeat the side effect.
614
615
615− self.last_insert.0 = self.keymap[&mode][&key];
616+ self.last_insert.0 = self.keymap[&mode][&key];
616− self.last_insert.1.clear();
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+ _ => (),
617− };
624+ }
618
625
619 EventResult::Consumed(callback)
626 EventResult::Consumed(callback)
620 }
627 }
helix-term/src/ui/picker.rs+2−4
@@ -122,14 +122,12 @@ fn inner_rect(area: Rect) -> Rect {
122 let padding_vertical = area.height * 20 / 100;
122 let padding_vertical = area.height * 20 / 100;
123 let padding_horizontal = area.width * 20 / 100;
123 let padding_horizontal = area.width * 20 / 100;
124
124
125− let area = Rect::new(
125+ Rect::new(
126 area.x + padding_horizontal,
126 area.x + padding_horizontal,
127 area.y + padding_vertical,
127 area.y + padding_vertical,
128 area.width - padding_horizontal * 2,
128 area.width - padding_horizontal * 2,
129 area.height - padding_vertical * 2,
129 area.height - padding_vertical * 2,
130− );
130+ )
131−
132− area
133}
131}
134
132
135impl<T: 'static> Component for Picker<T> {
133impl<T: 'static> Component for Picker<T> {