summaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs37
-rw-r--r--helix-view/src/macros.rs16
2 files changed, 51 insertions, 2 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 72140ea8..60864e9e 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -13,10 +13,12 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
use std::{
collections::HashMap,
path::{Path, PathBuf},
+ pin::Pin,
sync::Arc,
- time::Duration,
};
+use tokio::time::{sleep, Duration, Instant, Sleep};
+
use slotmap::SlotMap;
use anyhow::Error;
@@ -29,6 +31,14 @@ use helix_dap as dap;
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)]
#[serde(rename_all = "kebab-case", default)]
pub struct Config {
@@ -42,12 +52,17 @@ pub struct Config {
pub shell: Vec<String>,
/// Line number mode.
pub line_number: LineNumber,
- /// Middle click paste support. Defaults to true
+ /// Middle click paste support. Defaults to true.
pub middle_click_paste: bool,
/// Smart case: Case insensitive searching unless pattern contains upper case characters. Defaults to true.
pub smart_case: bool,
/// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true.
pub auto_pairs: bool,
+ /// Automatic auto-completion, automatically pop up without user trigger. Defaults to true.
+ pub auto_completion: 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)]
@@ -75,6 +90,8 @@ impl Default for Config {
middle_click_paste: true,
smart_case: true,
auto_pairs: true,
+ auto_completion: true,
+ idle_timeout: Duration::from_millis(400),
}
}
}
@@ -105,6 +122,8 @@ pub struct Editor {
pub status_msg: Option<(String, Severity)>,
pub config: Config,
+
+ pub idle_timer: Pin<Box<Sleep>>,
}
#[derive(Debug, Copy, Clone)]
@@ -146,10 +165,24 @@ impl Editor {
registers: Registers::default(),
clipboard_provider: get_clipboard_provider(),
status_msg: None,
+ idle_timer: Box::pin(sleep(config.idle_timeout)),
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() + self.config.idle_timeout);
+ }
+
pub fn clear_status(&mut self) {
self.status_msg = None;
}
diff --git a/helix-view/src/macros.rs b/helix-view/src/macros.rs
index c9a04270..0bebd02f 100644
--- a/helix-view/src/macros.rs
+++ b/helix-view/src/macros.rs
@@ -44,3 +44,19 @@ macro_rules! view {
$( $editor ).+ .tree.get($( $editor ).+ .tree.focus)
}};
}
+
+#[macro_export]
+macro_rules! doc {
+ ( $( $editor:ident ).+ ) => {{
+ $crate::current_ref!( $( $editor ).+ ).1
+ }};
+}
+
+#[macro_export]
+macro_rules! current_ref {
+ ( $( $editor:ident ).+ ) => {{
+ let view = $( $editor ).+ .tree.get($( $editor ).+ .tree.focus);
+ let doc = &$( $editor ).+ .documents[view.doc];
+ (view, doc)
+ }};
+}