mirror of https://github.com/lapce/lapce.git
Merge pull request #825 from panekj/feat/blink-interval
feat: add config option for cursor blink interval
This commit is contained in:
commit
c2ad7f33de
|
@ -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
|
||||
|
||||
|
|
|
@ -22,6 +22,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 = ""
|
||||
|
|
|
@ -203,6 +203,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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue