From 31b8b0deecd233dfc785afdf1850703eb59a83fe Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sat, 8 Oct 2022 23:55:56 +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 c7d98fcec0dd..4bb36b59cf4f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -435,18 +435,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 97639ff24e50..81f76d4b2784 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1016,7 +1016,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.mode != Mode::Insert || !cx.editor.config().auto_completion @@ -1024,15 +1024,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) } @@ -1353,6 +1345,7 @@ impl Component for EditorView { } Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), + Event::IdleTimeout => self.handle_idle_timeout(&mut cx), Event::FocusGained | Event::FocusLost => EventResult::Ignored(None), } } diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 083a1e0849e0..30fa72c49653 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -14,6 +14,7 @@ pub enum Event { Mouse(MouseEvent), Paste(String), Resize(u16, u16), + IdleTimeout, } #[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]