feat: add config option for cursor blink interval

This commit is contained in:
Jakub Panek 2022-07-19 15:32:24 +00:00 committed by GitHub
parent 7a9e58778d
commit a198818b54
3 changed files with 25 additions and 9 deletions

View File

@ -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 = ""

View File

@ -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 {

View File

@ -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);
}
}