Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent completion menu after navigation in insert mode #5803

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -879,7 +884,8 @@ impl EditorView {
}
}
_ => unreachable!(),
}
},
None => cx.editor.last_event_is_char = false,
}
}

Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@ pub struct Editor {
pub next_document_id: DocumentId,
pub documents: BTreeMap<DocumentId, Document>,

// 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,
p1gp1g marked this conversation as resolved.
Show resolved Hide resolved

// 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<DocumentId, UnboundedSender<Once<DocumentSavedEventFuture>>>,
Expand Down Expand Up @@ -1062,6 +1066,7 @@ impl Editor {
needs_redraw: false,
cursor_cache: Cell::new(None),
completion_request_handle: None,
last_event_is_char: false,
}
}

Expand Down
Loading