Propagate idle timeout event to components (#3172)

pull/4192/head
Gokul Soumya 2 years ago committed by GitHub
parent 5e1c589d43
commit 001858b11f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -435,18 +435,13 @@ impl Application {
} }
pub fn handle_idle_timeout(&mut self) { pub fn handle_idle_timeout(&mut self) {
use crate::compositor::EventResult;
let editor_view = self
.compositor
.find::<ui::EditorView>()
.expect("expected at least one EditorView");
let mut cx = crate::compositor::Context { let mut cx = crate::compositor::Context {
editor: &mut self.editor, editor: &mut self.editor,
jobs: &mut self.jobs, jobs: &mut self.jobs,
scroll: None, 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(); self.render();
} }
} }

@ -1066,7 +1066,7 @@ impl EditorView {
editor.clear_idle_timer(); // don't retrigger 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() if self.completion.is_some()
|| cx.editor.mode != Mode::Insert || cx.editor.mode != Mode::Insert
|| !cx.editor.config().auto_completion || !cx.editor.config().auto_completion
@ -1074,15 +1074,7 @@ impl EditorView {
return EventResult::Ignored(None); return EventResult::Ignored(None);
} }
let mut cx = commands::Context { crate::commands::insert::idle_completion(cx);
register: None,
editor: cx.editor,
jobs: cx.jobs,
count: None,
callback: None,
on_next_key_callback: None,
};
crate::commands::insert::idle_completion(&mut cx);
EventResult::Consumed(None) EventResult::Consumed(None)
} }
@ -1403,6 +1395,7 @@ impl Component for EditorView {
} }
Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), 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), Event::FocusGained | Event::FocusLost => EventResult::Ignored(None),
} }
} }

@ -14,6 +14,7 @@ pub enum Event {
Mouse(MouseEvent), Mouse(MouseEvent),
Paste(String), Paste(String),
Resize(u16, u16), Resize(u16, u16),
IdleTimeout,
} }
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)] #[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]

Loading…
Cancel
Save