From 5948ea217bcf8b220098b45e74e7a9e7fb492421 Mon Sep 17 00:00:00 2001 From: Vedant Matanhelia Date: Wed, 4 Dec 2024 21:53:31 +0530 Subject: [PATCH] Configure Highlight settings on yank vim (#21479) Release Notes: - Add settings / config variables to control `highlight_on_yank` or `highlight_on_copy` --------- Co-authored-by: Conrad Irwin --- assets/settings/default.json | 1 + crates/vim/src/normal/yank.rs | 8 +++++--- crates/vim/src/vim.rs | 2 ++ docs/src/vim.md | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 5930537856..97e05c9ad5 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1129,6 +1129,7 @@ "use_system_clipboard": "always", "use_multiline_find": false, "use_smartcase_find": false, + "highlight_on_yank_duration": 200, "custom_digraphs": {} }, // The server to connect to. If the environment variable diff --git a/crates/vim/src/normal/yank.rs b/crates/vim/src/normal/yank.rs index 85c6531f6a..d23dc2f9b0 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -4,13 +4,14 @@ use crate::{ motion::Motion, object::Object, state::{Mode, Register}, - Vim, + Vim, VimSettings, }; use collections::HashMap; use editor::{ClipboardSelection, Editor}; use gpui::ViewContext; use language::Point; use multi_buffer::MultiBufferRow; +use settings::Settings; struct HighlightOnYank; @@ -195,7 +196,8 @@ impl Vim { ) }); - if !is_yank || self.mode == Mode::Visual { + let highlight_duration = VimSettings::get_global(cx).highlight_on_yank_duration; + if !is_yank || self.mode == Mode::Visual || highlight_duration == 0 { return; } @@ -206,7 +208,7 @@ impl Vim { ); cx.spawn(|this, mut cx| async move { cx.background_executor() - .timer(Duration::from_millis(200)) + .timer(Duration::from_millis(highlight_duration)) .await; this.update(&mut cx, |editor, cx| { editor.clear_background_highlights::(cx) diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index c395e9c37e..843b094700 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1199,6 +1199,7 @@ struct VimSettings { pub use_multiline_find: bool, pub use_smartcase_find: bool, pub custom_digraphs: HashMap>, + pub highlight_on_yank_duration: u64, } #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] @@ -1208,6 +1209,7 @@ struct VimSettingsContent { pub use_multiline_find: Option, pub use_smartcase_find: Option, pub custom_digraphs: Option>>, + pub highlight_on_yank_duration: Option, } impl Settings for VimSettings { diff --git a/docs/src/vim.md b/docs/src/vim.md index c0a7fed2e2..a350fb7773 100644 --- a/docs/src/vim.md +++ b/docs/src/vim.md @@ -438,6 +438,7 @@ You can change the following settings to modify vim mode's behavior: | use_smartcase_find | If `true`, `f` and `t` motions are case-insensitive when the target letter is lowercase. | false | | toggle_relative_line_numbers | If `true`, line numbers are relative in normal mode and absolute in insert mode, giving you the best of both options. | false | | custom_digraphs | An object that allows you to add custom digraphs. Read below for an example. | {} | +| highlight_on_yank_duration | The duration of the highlight animation(in ms). Set to `0` to disable | 200 | Here's an example of adding a digraph for the zombie emoji. This allows you to type `ctrl-k f z` to insert a zombie emoji. You can add as many digraphs as you like. @@ -460,6 +461,7 @@ Here's an example of these settings changed: "use_multiline_find": true, "use_smartcase_find": true, "toggle_relative_line_numbers": true, + "highlight_on_yank_duration": 50, "custom_digraphs": { "fz": "🧟‍♀️" }