|
|
@ -9,10 +9,12 @@ use crate::{
|
|
|
|
use futures_util::future;
|
|
|
|
use futures_util::future;
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
|
|
|
|
pin::Pin,
|
|
|
|
sync::Arc,
|
|
|
|
sync::Arc,
|
|
|
|
time::Duration,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use tokio::time::{sleep, Duration, Instant, Sleep};
|
|
|
|
|
|
|
|
|
|
|
|
use slotmap::SlotMap;
|
|
|
|
use slotmap::SlotMap;
|
|
|
|
|
|
|
|
|
|
|
|
use anyhow::Error;
|
|
|
|
use anyhow::Error;
|
|
|
@ -24,6 +26,14 @@ use helix_core::Position;
|
|
|
|
|
|
|
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let millis = u64::deserialize(deserializer)?;
|
|
|
|
|
|
|
|
Ok(Duration::from_millis(millis))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "kebab-case", default)]
|
|
|
|
#[serde(rename_all = "kebab-case", default)]
|
|
|
|
pub struct Config {
|
|
|
|
pub struct Config {
|
|
|
@ -43,6 +53,9 @@ pub struct Config {
|
|
|
|
pub smart_case: bool,
|
|
|
|
pub smart_case: bool,
|
|
|
|
/// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true.
|
|
|
|
/// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true.
|
|
|
|
pub auto_pairs: bool,
|
|
|
|
pub auto_pairs: bool,
|
|
|
|
|
|
|
|
/// Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. Defaults to 400ms.
|
|
|
|
|
|
|
|
#[serde(skip_serializing, deserialize_with = "deserialize_duration_millis")]
|
|
|
|
|
|
|
|
pub idle_timeout: Duration,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
|
@ -70,6 +83,7 @@ impl Default for Config {
|
|
|
|
middle_click_paste: true,
|
|
|
|
middle_click_paste: true,
|
|
|
|
smart_case: true,
|
|
|
|
smart_case: true,
|
|
|
|
auto_pairs: true,
|
|
|
|
auto_pairs: true,
|
|
|
|
|
|
|
|
idle_timeout: Duration::from_millis(400),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,6 +105,8 @@ pub struct Editor {
|
|
|
|
pub status_msg: Option<(String, Severity)>,
|
|
|
|
pub status_msg: Option<(String, Severity)>,
|
|
|
|
|
|
|
|
|
|
|
|
pub config: Config,
|
|
|
|
pub config: Config,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub idle_timer: Pin<Box<Sleep>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
@ -125,10 +141,24 @@ impl Editor {
|
|
|
|
registers: Registers::default(),
|
|
|
|
registers: Registers::default(),
|
|
|
|
clipboard_provider: get_clipboard_provider(),
|
|
|
|
clipboard_provider: get_clipboard_provider(),
|
|
|
|
status_msg: None,
|
|
|
|
status_msg: None,
|
|
|
|
|
|
|
|
idle_timer: Box::pin(sleep(Duration::from_millis(500))),
|
|
|
|
config,
|
|
|
|
config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn clear_idle_timer(&mut self) {
|
|
|
|
|
|
|
|
// equivalent to internal Instant::far_future() (30 years)
|
|
|
|
|
|
|
|
self.idle_timer
|
|
|
|
|
|
|
|
.as_mut()
|
|
|
|
|
|
|
|
.reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn reset_idle_timer(&mut self) {
|
|
|
|
|
|
|
|
self.idle_timer
|
|
|
|
|
|
|
|
.as_mut()
|
|
|
|
|
|
|
|
.reset(Instant::now() + Duration::from_millis(500));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn clear_status(&mut self) {
|
|
|
|
pub fn clear_status(&mut self) {
|
|
|
|
self.status_msg = None;
|
|
|
|
self.status_msg = None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|