Skip to content

Commit

Permalink
create separate timer for redraw requests (helix-editor#8023)
Browse files Browse the repository at this point in the history
* create separate timer for redraw requests

* Update helix-view/src/editor.rs

Co-authored-by: Michael Davis <[email protected]>

---------

Co-authored-by: Michael Davis <[email protected]>
  • Loading branch information
2 people authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 8239b2c commit 46cc5bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ impl Application {
self.render().await;
}
}
EditorEvent::Redraw => {
self.render().await;
}
EditorEvent::IdleTimer => {
self.editor.clear_idle_timer();
self.handle_idle_timeout().await;
Expand Down
11 changes: 9 additions & 2 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ pub struct Editor {
pub auto_pairs: Option<AutoPairs>,

pub idle_timer: Pin<Box<Sleep>>,
redraw_timer: Pin<Box<Sleep>>,
last_motion: Option<Motion>,
pub last_completion: Option<CompleteAction>,

Expand Down Expand Up @@ -963,6 +964,7 @@ pub enum EditorEvent {
LanguageServerMessage((usize, Call)),
DebuggerEvent(dap::Payload),
IdleTimer,
Redraw,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1053,6 +1055,7 @@ impl Editor {
status_msg: None,
autoinfo: None,
idle_timer: Box::pin(sleep(conf.idle_timeout)),
redraw_timer: Box::pin(sleep(Duration::MAX)),
last_motion: None,
last_completion: None,
config,
Expand Down Expand Up @@ -1753,12 +1756,16 @@ impl Editor {
if !self.needs_redraw{
self.needs_redraw = true;
let timeout = Instant::now() + Duration::from_millis(33);
if timeout < self.idle_timer.deadline(){
self.idle_timer.as_mut().reset(timeout)
if timeout < self.idle_timer.deadline() && timeout < self.redraw_timer.deadline(){
self.redraw_timer.as_mut().reset(timeout)
}
}
}

_ = &mut self.redraw_timer => {
self.redraw_timer.as_mut().reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
return EditorEvent::Redraw
}
_ = &mut self.idle_timer => {
return EditorEvent::IdleTimer
}
Expand Down

0 comments on commit 46cc5bc

Please sign in to comment.