diff --git a/defaults/settings.toml b/defaults/settings.toml index 9c2479d4..8b6c8a0e 100644 --- a/defaults/settings.toml +++ b/defaults/settings.toml @@ -21,6 +21,7 @@ enable-error-lens = true error-lens-end-of-line = true error-lens-font-family = "" error-lens-font-size = 0 +blink-interval = 500 # ms [terminal] font-family = "" diff --git a/lapce-data/src/config.rs b/lapce-data/src/config.rs index 5e2fef03..79c6384d 100644 --- a/lapce-data/src/config.rs +++ b/lapce-data/src/config.rs @@ -199,6 +199,10 @@ pub struct EditorConfig { desc = "Set the error lens font size. If 0 it uses the inlay hint font size." )] pub error_lens_font_size: usize, + #[field_names( + desc = "Set the cursor blink interval (in milliseconds). Set to 0 to completely disable." + )] + pub blink_interval: u64, // TODO: change to u128 when upgrading config-rs to >0.11 } impl EditorConfig { diff --git a/lapce-ui/src/editor.rs b/lapce-ui/src/editor.rs index 8c0aa9d6..53375d3c 100644 --- a/lapce-ui/src/editor.rs +++ b/lapce-ui/src/editor.rs @@ -1860,16 +1860,27 @@ fn layout( fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let is_focused = data.focus == self.view_id; let data = data.editor_view_content(self.view_id); + + // TODO: u128 is supported by config-rs since 0.12.0, but also the API changed heavily, + // casting blink_interval to u128 for now but can be removed once config-rs is bumped + /* + is_focus is used in paint_cursor_new to decide whether to draw cursor (and animate it / "blink") + cursor will blink based if below conditions are true: + - editor is focused + - blink_interval is not 0 + - time since last blink is exact to blink_interval + */ let is_focused = is_focused - && (data - .editor - .last_cursor_instant - .borrow() - .elapsed() - .as_millis() - / 500) - % 2 - == 0; + && (data.config.editor.blink_interval == 0 + || (data + .editor + .last_cursor_instant + .borrow() + .elapsed() + .as_millis() + / data.config.editor.blink_interval as u128) + % 2 + == 0); self.paint_content(&data, ctx, is_focused, env); } }