From f7f5a16f7f4f51f4b4801a3431bac4b4eaadce36 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sun, 24 Jul 2022 08:09:22 +0530 Subject: [PATCH] Propagate idle timeout event to components --- helix-term/src/application.rs | 9 ++------- helix-term/src/ui/editor.rs | 13 +++---------- helix-view/src/input.rs | 1 + 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index a019188989f11..250399b6ad6ac 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -402,18 +402,13 @@ impl Application { } pub fn handle_idle_timeout(&mut self) { - use crate::compositor::EventResult; - let editor_view = self - .compositor - .find::() - .expect("expected at least one EditorView"); - let mut cx = crate::compositor::Context { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, }; - if let EventResult::Consumed(_) = editor_view.handle_idle_timeout(&mut cx) { + let should_render = self.compositor.handle_event(Event::IdleTimeout, &mut cx); + if should_render { self.render(); } } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index a5774132cd7ec..0b12e6edbbd64 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -889,7 +889,7 @@ impl EditorView { editor.clear_idle_timer(); // don't retrigger } - pub fn handle_idle_timeout(&mut self, cx: &mut crate::compositor::Context) -> EventResult { + pub fn handle_idle_timeout(&mut self, cx: &mut commands::Context) -> EventResult { if self.completion.is_some() || !cx.editor.config().auto_completion || doc!(cx.editor).mode != Mode::Insert @@ -897,15 +897,7 @@ impl EditorView { return EventResult::Ignored(None); } - let mut cx = commands::Context { - register: None, - editor: cx.editor, - jobs: cx.jobs, - count: None, - callback: None, - on_next_key_callback: None, - }; - crate::commands::insert::idle_completion(&mut cx); + crate::commands::insert::idle_completion(cx); EventResult::Consumed(None) } @@ -1231,6 +1223,7 @@ impl Component for EditorView { } Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), + Event::IdleTimeout => self.handle_idle_timeout(&mut cx), } } diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 9ae3ce70aa24f..c5bfbdd7f70b6 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -11,6 +11,7 @@ pub enum Event { Key(KeyEvent), Mouse(MouseEvent), Resize(u16, u16), + IdleTimeout, } #[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]