From 65ab6f0c21d26f741114e1e745ba7e9d3d8e6596 Mon Sep 17 00:00:00 2001 From: sim Date: Fri, 3 Feb 2023 11:20:46 +0100 Subject: [PATCH 1/2] Prevent completion menu after navigation in insert mode --- helix-term/src/ui/editor.rs | 25 +++++++++++++++++-------- helix-view/src/editor.rs | 3 +++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 31195a4e557a..d3797882dbee 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -857,18 +857,23 @@ impl EditorView { } fn insert_mode(&mut self, cx: &mut commands::Context, event: KeyEvent) { - if let Some(keyresult) = self.handle_keymap_event(Mode::Insert, cx, event) { - match keyresult { - KeymapResult::NotFound => { - if let Some(ch) = event.char() { - commands::insert::insert_char(cx, ch) + match self.handle_keymap_event(Mode::Insert, cx, event) { + Some(keyresult) => match keyresult { + KeymapResult::NotFound => match event.char() { + Some(ch) => { + cx.editor.last_event_is_char = true; + commands::insert::insert_char(cx, ch); } - } + None => { + cx.editor.last_event_is_char = false; + } + }, KeymapResult::Cancelled(pending) => { for ev in pending { match ev.char() { Some(ch) => commands::insert::insert_char(cx, ch), None => { + cx.editor.last_event_is_char = false; if let KeymapResult::Matched(command) = self.keymaps.get(Mode::Insert, ev) { @@ -879,7 +884,8 @@ impl EditorView { } } _ => unreachable!(), - } + }, + None => cx.editor.last_event_is_char = false, } } @@ -1020,7 +1026,10 @@ impl EditorView { }; } - if cx.editor.mode != Mode::Insert || !cx.editor.config().auto_completion { + if cx.editor.mode != Mode::Insert + || !cx.editor.last_event_is_char + || !cx.editor.config().auto_completion + { return EventResult::Ignored(None); } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 7af28ccc680a..8efc557b5a12 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -881,6 +881,8 @@ pub struct Editor { pub next_document_id: DocumentId, pub documents: BTreeMap, + pub last_event_is_char: bool, + // We Flatten<> to resolve the inner DocumentSavedEventFuture. For that we need a stream of streams, hence the Once<>. // https://stackoverflow.com/a/66875668 pub saves: HashMap>>, @@ -1062,6 +1064,7 @@ impl Editor { needs_redraw: false, cursor_cache: Cell::new(None), completion_request_handle: None, + last_event_is_char: false, } } From 8d9b92f092e043b6198a810bec2614482e8c4580 Mon Sep 17 00:00:00 2001 From: sim Date: Sun, 5 Feb 2023 16:59:27 +0100 Subject: [PATCH 2/2] Add comment about last_event_is_char --- helix-view/src/editor.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 8efc557b5a12..6b309f450a2f 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -881,6 +881,8 @@ pub struct Editor { pub next_document_id: DocumentId, pub documents: BTreeMap, + // To know if the user is currently inserting chars or moving in Insert Mode + // https://github.com/helix-editor/helix/pull/5803 pub last_event_is_char: bool, // We Flatten<> to resolve the inner DocumentSavedEventFuture. For that we need a stream of streams, hence the Once<>.