From f99bea404f43ea0e373fd9fe54616d3282e8364b Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 22 Aug 2021 15:28:45 +0900 Subject: idle timer wip --- helix-view/src/editor.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'helix-view/src/editor.rs') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index b08a2df2..5362acc8 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -9,10 +9,12 @@ use crate::{ use futures_util::future; use std::{ path::{Path, PathBuf}, + pin::Pin, sync::Arc, - time::Duration, }; +use tokio::time::{sleep, Duration, Instant, Sleep}; + use slotmap::SlotMap; use anyhow::Error; @@ -91,6 +93,8 @@ pub struct Editor { pub status_msg: Option<(String, Severity)>, pub config: Config, + + pub idle_timer: Pin>, } #[derive(Debug, Copy, Clone)] @@ -125,10 +129,24 @@ impl Editor { registers: Registers::default(), clipboard_provider: get_clipboard_provider(), status_msg: None, + idle_timer: Box::pin(sleep(Duration::from_millis(500))), 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) { self.status_msg = None; } -- cgit v1.2.3-70-g09d2 From 633b981db22bb30c601b838eaaeb814a64156125 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 10 Oct 2021 12:32:06 +0900 Subject: Make idle-timeout configurable --- book/src/configuration.md | 1 + helix-term/src/commands.rs | 11 +++++++++-- helix-view/src/editor.rs | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'helix-view/src/editor.rs') diff --git a/book/src/configuration.md b/book/src/configuration.md index 60b12bfd..f30146dd 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -19,6 +19,7 @@ To override global configuration parameters, create a `config.toml` file located | `line-number` | Line number display (`absolute`, `relative`) | `absolute` | | `smart-case` | Enable smart case regex searching (case insensitive unless pattern contains upper case characters) | `true` | | `auto-pairs` | Enable automatic insertion of pairs to parenthese, brackets, etc. | `true` | +| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` | ## LSP diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3798c99a..f005e376 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4130,7 +4130,7 @@ pub fn completion(cx: &mut Context) { }; if items.is_empty() { - editor.set_error("No completion available".to_string()); + // editor.set_error("No completion available".to_string()); return; } let size = compositor.size(); @@ -4138,7 +4138,14 @@ pub fn completion(cx: &mut Context) { .find(std::any::type_name::()) .unwrap(); if let Some(ui) = ui.as_any_mut().downcast_mut::() { - ui.set_completion(editor, items, offset_encoding, start_offset, trigger_offset, size); + ui.set_completion( + editor, + items, + offset_encoding, + start_offset, + trigger_offset, + size, + ); }; }, ); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 5362acc8..5af6dbf3 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -26,6 +26,14 @@ use helix_core::Position; use serde::Deserialize; +fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result +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 { @@ -45,6 +53,9 @@ pub struct Config { pub smart_case: bool, /// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true. 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)] @@ -72,6 +83,7 @@ impl Default for Config { middle_click_paste: true, smart_case: true, auto_pairs: true, + idle_timeout: Duration::from_millis(400), } } } -- cgit v1.2.3-70-g09d2