Merge pull request #825 from panekj/feat/blink-interval

feat: add config option for cursor blink interval
This commit is contained in:
Dongdong Zhou 2022-07-19 20:24:19 +01:00 committed by GitHub
commit c2ad7f33de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

View File

@ -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 \ gtk+3.0-dev libgit2-dev libssh2-dev libxcb-dev \
libxfixes-dev libxkbcommon-dev openssl-dev python3 \ libxfixes-dev libxkbcommon-dev openssl-dev python3 \
vulkan-loader-dev wayland-dev curl wget alpine-sdk \ 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 RUN echo "permit nopass :wheel" > /etc/doas.d/doas.conf

View File

@ -22,6 +22,7 @@ enable-error-lens = true
error-lens-end-of-line = true error-lens-end-of-line = true
error-lens-font-family = "" error-lens-font-family = ""
error-lens-font-size = 0 error-lens-font-size = 0
blink-interval = 500 # ms
[terminal] [terminal]
font-family = "" font-family = ""

View File

@ -203,6 +203,10 @@ pub struct EditorConfig {
desc = "Set the error lens font size. If 0 it uses the inlay hint font size." desc = "Set the error lens font size. If 0 it uses the inlay hint font size."
)] )]
pub error_lens_font_size: usize, 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 { impl EditorConfig {

View File

@ -1860,16 +1860,27 @@ fn layout(
fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {
let is_focused = data.focus == self.view_id; let is_focused = data.focus == self.view_id;
let data = data.editor_view_content(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 let is_focused = is_focused
&& (data && (data.config.editor.blink_interval == 0
.editor || (data
.last_cursor_instant .editor
.borrow() .last_cursor_instant
.elapsed() .borrow()
.as_millis() .elapsed()
/ 500) .as_millis()
% 2 / data.config.editor.blink_interval as u128)
== 0; % 2
== 0);
self.paint_content(&data, ctx, is_focused, env); self.paint_content(&data, ctx, is_focused, env);
} }
} }