@@ -9,10 +9,12 @@ use crate::{
99use futures_util::future;
1010use std::{
1111 path::{Path, PathBuf},
12+ pin::Pin,
1213 sync::Arc,
13− time::Duration,
1414};
1515
16+use tokio::time::{sleep, Duration, Instant, Sleep};
17+
1618use slotmap::SlotMap;
1719
1820use anyhow::Error;
@@ -91,6 +93,8 @@ pub struct Editor {
9193 pub status_msg: Option<(String, Severity)>,
9294
9395 pub config: Config,
96+
97+ pub idle_timer: Pin<Box<Sleep>>,
9498}
9599
96100#[derive(Debug, Copy, Clone)]
@@ -125,10 +129,24 @@ impl Editor {
125129 registers: Registers::default(),
126130 clipboard_provider: get_clipboard_provider(),
127131 status_msg: None,
132+ idle_timer: Box::pin(sleep(Duration::from_millis(500))),
128133 config,
129134 }
130135 }
131136
137+ pub fn clear_idle_timer(&mut self) {
138+ // equivalent to internal Instant::far_future() (30 years)
139+ self.idle_timer
140+ .as_mut()
141+ .reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
142+ }
143+
144+ pub fn reset_idle_timer(&mut self) {
145+ self.idle_timer
146+ .as_mut()
147+ .reset(Instant::now() + Duration::from_millis(500));
148+ }
149+
132150 pub fn clear_status(&mut self) {
133151 self.status_msg = None;
134152 }