Skip to content

Commit

Permalink
Propagate idle timeout event to components
Browse files Browse the repository at this point in the history
  • Loading branch information
sudormrfbin committed Jul 24, 2022
1 parent bcdd44f commit f7f5a16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
9 changes: 2 additions & 7 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,13 @@ impl Application {
}

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 {
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();
}
}
Expand Down
13 changes: 3 additions & 10 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,23 +889,15 @@ 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
{
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)
}
Expand Down Expand Up @@ -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),
}
}

Expand Down
1 change: 1 addition & 0 deletions helix-view/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum Event {
Key(KeyEvent),
Mouse(MouseEvent),
Resize(u16, u16),
IdleTimeout,
}

#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
Expand Down

0 comments on commit f7f5a16

Please sign in to comment.