From 3c2d3ee3feb247250211f41e3114cab0e1fb0694 Mon Sep 17 00:00:00 2001 From: RustyDev Date: Tue, 3 Dec 2024 23:16:24 +0530 Subject: [PATCH 1/8] feat: add highligh on copy config --- assets/settings/default.json | 1 + crates/vim/src/normal/yank.rs | 7 +++++-- crates/vim/src/vim.rs | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 5930537856393..c2326ad3904d6 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_copy": false, "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 763f1a3d16d4d..7becefc9543de 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,9 @@ impl Vim { ) }); - if !is_yank || self.mode == Mode::Visual { + let highlight = VimSettings::get_global(cx).highlight_on_copy; + + if !is_yank || self.mode == Mode::Visual || !highlight { return; } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index db0a7651704a1..2263e7a8cc4b9 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1188,6 +1188,7 @@ struct VimSettings { pub use_multiline_find: bool, pub use_smartcase_find: bool, pub custom_digraphs: HashMap>, + pub highlight_on_copy: bool, } #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] @@ -1197,6 +1198,7 @@ struct VimSettingsContent { pub use_multiline_find: Option, pub use_smartcase_find: Option, pub custom_digraphs: Option>>, + pub highlight_on_copy: Option, } impl Settings for VimSettings { From 9aad1d5094be59c9ebd7603fbc0ff7e3c917f48f Mon Sep 17 00:00:00 2001 From: RustyDev Date: Tue, 3 Dec 2024 23:21:50 +0530 Subject: [PATCH 2/8] feat: add highlight on copy config --- assets/settings/default.json | 3 ++- crates/vim/src/normal/yank.rs | 4 +++- crates/vim/src/vim.rs | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index c2326ad3904d6..256ab8d29432b 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1129,7 +1129,8 @@ "use_system_clipboard": "always", "use_multiline_find": false, "use_smartcase_find": false, - "highlight_on_copy": false, + "highlight_on_copy": true, + "highlight_on_copy_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 7becefc9543de..f1463037dd709 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -202,6 +202,8 @@ impl Vim { return; } + let highlight_duration = VimSettings::get_global(cx).highlight_on_copy_duration; + editor.highlight_background::( &ranges_to_highlight, |colors| colors.editor_document_highlight_read_background, @@ -209,7 +211,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 2263e7a8cc4b9..89085951c3ca1 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1189,6 +1189,7 @@ struct VimSettings { pub use_smartcase_find: bool, pub custom_digraphs: HashMap>, pub highlight_on_copy: bool, + pub highlight_on_copy_duration: u64, } #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] @@ -1199,6 +1200,7 @@ struct VimSettingsContent { pub use_smartcase_find: Option, pub custom_digraphs: Option>>, pub highlight_on_copy: Option, + pub highlight_on_copy_duration: Option, } impl Settings for VimSettings { From eb9b97dbdad15cce1a1fb778a12ba31d10e1515a Mon Sep 17 00:00:00 2001 From: RustyDev Date: Tue, 3 Dec 2024 23:39:54 +0530 Subject: [PATCH 3/8] feat: remove unused --- assets/settings/default.json | 1 - crates/vim/src/normal/yank.rs | 7 ++----- crates/vim/src/vim.rs | 2 -- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 256ab8d29432b..fd412075afa1a 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1129,7 +1129,6 @@ "use_system_clipboard": "always", "use_multiline_find": false, "use_smartcase_find": false, - "highlight_on_copy": true, "highlight_on_copy_duration": 200, "custom_digraphs": {} }, diff --git a/crates/vim/src/normal/yank.rs b/crates/vim/src/normal/yank.rs index f1463037dd709..4011ec114ddd2 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -196,14 +196,11 @@ impl Vim { ) }); - let highlight = VimSettings::get_global(cx).highlight_on_copy; - - if !is_yank || self.mode == Mode::Visual || !highlight { + let highlight_duration = VimSettings::get_global(cx).highlight_on_copy_duration; + if !is_yank || self.mode == Mode::Visual || highlight_duration == 0 { return; } - let highlight_duration = VimSettings::get_global(cx).highlight_on_copy_duration; - editor.highlight_background::( &ranges_to_highlight, |colors| colors.editor_document_highlight_read_background, diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 89085951c3ca1..331d5cf676cec 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1188,7 +1188,6 @@ struct VimSettings { pub use_multiline_find: bool, pub use_smartcase_find: bool, pub custom_digraphs: HashMap>, - pub highlight_on_copy: bool, pub highlight_on_copy_duration: u64, } @@ -1199,7 +1198,6 @@ struct VimSettingsContent { pub use_multiline_find: Option, pub use_smartcase_find: Option, pub custom_digraphs: Option>>, - pub highlight_on_copy: Option, pub highlight_on_copy_duration: Option, } From 1da1146ec3d79e1f35a119e148f997b7bd84a1ca Mon Sep 17 00:00:00 2001 From: RustyDev Date: Tue, 3 Dec 2024 23:39:59 +0530 Subject: [PATCH 4/8] feat: docs --- docs/src/vim.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/vim.md b/docs/src/vim.md index 254c5a09346ce..40730f98ed4c2 100644 --- a/docs/src/vim.md +++ b/docs/src/vim.md @@ -409,6 +409,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_copy_duration | The duration of the higlight animation. 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. From 544f94735adfbc714e044eca5771a80c8f41df04 Mon Sep 17 00:00:00 2001 From: RustyDev Date: Tue, 3 Dec 2024 23:52:30 +0530 Subject: [PATCH 5/8] feat: docs --- docs/src/vim.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/vim.md b/docs/src/vim.md index 40730f98ed4c2..a7036ec29894e 100644 --- a/docs/src/vim.md +++ b/docs/src/vim.md @@ -409,7 +409,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_copy_duration | The duration of the higlight animation. Set to `0` to disable | 200 | +| highlight_on_copy_duration | The duration of the higlight 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. @@ -432,6 +432,7 @@ Here's an example of these settings changed: "use_multiline_find": true, "use_smartcase_find": true, "toggle_relative_line_numbers": true, + "highlight_on_copy_duration": 50, "custom_digraphs": { "fz": "🧟‍♀️" } From 455cfd9f73b7a558b8154c4d6a39ba0be8cdac1e Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 3 Dec 2024 13:28:30 -0700 Subject: [PATCH 6/8] highlight_on_copy -> highlight_on_yank --- assets/settings/default.json | 2 +- crates/vim/src/normal/yank.rs | 2 +- crates/vim/src/vim.rs | 4 ++-- docs/src/vim.md | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index fd412075afa1a..97e05c9ad56dd 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1129,7 +1129,7 @@ "use_system_clipboard": "always", "use_multiline_find": false, "use_smartcase_find": false, - "highlight_on_copy_duration": 200, + "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 4011ec114ddd2..09aac924a70d9 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -196,7 +196,7 @@ impl Vim { ) }); - let highlight_duration = VimSettings::get_global(cx).highlight_on_copy_duration; + let highlight_duration = VimSettings::get_global(cx).highlight_on_yank_duration; if !is_yank || self.mode == Mode::Visual || highlight_duration == 0 { return; } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 331d5cf676cec..7bc97519ff2d9 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -1188,7 +1188,7 @@ struct VimSettings { pub use_multiline_find: bool, pub use_smartcase_find: bool, pub custom_digraphs: HashMap>, - pub highlight_on_copy_duration: u64, + pub highlight_on_yank_duration: u64, } #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] @@ -1198,7 +1198,7 @@ struct VimSettingsContent { pub use_multiline_find: Option, pub use_smartcase_find: Option, pub custom_digraphs: Option>>, - pub highlight_on_copy_duration: Option, + pub highlight_on_yank_duration: Option, } impl Settings for VimSettings { diff --git a/docs/src/vim.md b/docs/src/vim.md index a7036ec29894e..e7af2660a1a07 100644 --- a/docs/src/vim.md +++ b/docs/src/vim.md @@ -409,7 +409,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_copy_duration | The duration of the higlight animation(in ms). Set to `0` to disable | 200 | +| highlight_on_yank_duration | The duration of the higlight 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. @@ -432,7 +432,7 @@ Here's an example of these settings changed: "use_multiline_find": true, "use_smartcase_find": true, "toggle_relative_line_numbers": true, - "highlight_on_copy_duration": 50, + "highlight_on_yank_duration": 50, "custom_digraphs": { "fz": "🧟‍♀️" } From fb50fe429202a589bb31dfed9e00906b55cab38f Mon Sep 17 00:00:00 2001 From: RustyDev Date: Wed, 4 Dec 2024 02:39:55 +0530 Subject: [PATCH 7/8] fix: typo --- docs/src/vim.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/vim.md b/docs/src/vim.md index a7036ec29894e..ecb1381a43183 100644 --- a/docs/src/vim.md +++ b/docs/src/vim.md @@ -409,7 +409,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_copy_duration | The duration of the higlight animation(in ms). Set to `0` to disable | 200 | +| highlight_on_copy_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. From b5ddaf1781f5b95827c1a520b35faa66db9ff1dc Mon Sep 17 00:00:00 2001 From: RustyDev Date: Wed, 4 Dec 2024 03:11:12 +0530 Subject: [PATCH 8/8] fix: typo --- docs/src/vim.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/vim.md b/docs/src/vim.md index 7610841797b9a..666d5a6be0d56 100644 --- a/docs/src/vim.md +++ b/docs/src/vim.md @@ -409,7 +409,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_copy_duration | The duration of the highlight animation(in ms). Set to `0` to disable | 200 | +| 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.