From 7a9e58778d032ffe81d2fbb3015eaa32073758ff Mon Sep 17 00:00:00 2001 From: Jakub Panek Date: Tue, 19 Jul 2022 15:30:26 +0000 Subject: [PATCH 1/2] feat: add missing rust components to devcontainer added rustfmt, rust-wasm, rust-analyzer, rust-clippy, etc. --- .devcontainer/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index bb200528..effc5d0c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,7 +10,8 @@ RUN apk add --no-cache doas cargo rust-src freetype-dev \ gtk+3.0-dev libgit2-dev libssh2-dev libxcb-dev \ libxfixes-dev libxkbcommon-dev openssl-dev python3 \ vulkan-loader-dev wayland-dev curl wget alpine-sdk \ - zsh fish bash less coreutils util-linux + zsh fish bash less coreutils util-linux rustfmt \ + rust-clippy rust-analyzer rust-doc rust-wasm RUN echo "permit nopass :wheel" > /etc/doas.d/doas.conf From a198818b54e8379ac401c08d75a1e867df7dff08 Mon Sep 17 00:00:00 2001 From: Jakub Panek Date: Tue, 19 Jul 2022 15:32:24 +0000 Subject: [PATCH 2/2] feat: add config option for cursor blink interval --- defaults/settings.toml | 1 + lapce-data/src/config.rs | 4 ++++ lapce-ui/src/editor.rs | 29 ++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 9 deletions(-) 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); } }