diff options
author | Blaž Hrastnik | 2021-10-10 13:11:01 +0000 |
---|---|---|
committer | GitHub | 2021-10-10 13:11:01 +0000 |
commit | f8f63c55081ee966c7cb2b84139c25c6301b5fff (patch) | |
tree | c4c74c5c013d8c26f6b9b124821fabd9200c3218 /helix-term/src/application.rs | |
parent | a7f49fa56fecd7f44efca7e6074e5cd9e5d91c92 (diff) | |
parent | 76b1bbc23ad5fc47765472cd9e83727a43c97ff3 (diff) |
Merge pull request #821 from helix-editor/idle-timer
Idle timer / Autocompletion
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r-- | helix-term/src/application.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 6206e6f2..c39a9173 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -199,6 +199,11 @@ impl Application { self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback); self.render(); } + _ = &mut self.editor.idle_timer => { + // idle timeout + self.editor.clear_idle_timer(); + self.handle_idle_timeout(); + } } } } @@ -228,6 +233,38 @@ impl Application { } } + pub fn handle_idle_timeout(&mut self) { + use crate::commands::{completion, Context}; + use helix_view::document::Mode; + + if doc_mut!(self.editor).mode != Mode::Insert { + return; + } + let editor_view = self + .compositor + .find(std::any::type_name::<ui::EditorView>()) + .expect("expected at least one EditorView"); + let editor_view = editor_view + .as_any_mut() + .downcast_mut::<ui::EditorView>() + .unwrap(); + + if editor_view.completion.is_some() { + return; + } + + let mut cx = Context { + register: None, + editor: &mut self.editor, + jobs: &mut self.jobs, + count: None, + callback: None, + on_next_key_callback: None, + }; + completion(&mut cx); + self.render(); + } + pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) { let mut cx = crate::compositor::Context { editor: &mut self.editor, |