vim: Add configurable yank highlight background color (#49517)

Kasper Nyhus and dino created

* Add a dedicated `vim.yank.background` theme color for the yank
  highlight, which was previously hardcoded to
  `editor.document_highlight.read_background`.
* When a theme doesn't define `vim.yank.background`, it falls back to
  `editor.document_highlight.read_background` for backwards
  compatibility.
* The VS Code theme importer maps `editor.rangeHighlightBackground` to
  this new color.

Release Notes:

- Added configurable `vim.yank.background` theme color for vim yank
  background highlight

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>

Change summary

crates/settings_content/src/theme.rs          | 3 +++
crates/theme/src/default_colors.rs            | 2 ++
crates/theme/src/fallback_themes.rs           | 1 +
crates/theme/src/schema.rs                    | 5 +++++
crates/theme/src/styles/colors.rs             | 2 ++
crates/theme_importer/src/vscode/converter.rs | 1 +
crates/vim/src/normal/yank.rs                 | 2 +-
7 files changed, 15 insertions(+), 1 deletion(-)

Detailed changes

crates/settings_content/src/theme.rs 🔗

@@ -1033,6 +1033,9 @@ pub struct ThemeColorsContent {
     /// Background color for Vim Visual Block mode indicator.
     #[serde(rename = "vim.visual_block.background")]
     pub vim_visual_block_background: Option<String>,
+    /// Background color for Vim yank highlight.
+    #[serde(rename = "vim.yank.background")]
+    pub vim_yank_background: Option<String>,
     /// Background color for Vim Helix Normal mode indicator.
     #[serde(rename = "vim.helix_normal.background")]
     pub vim_helix_normal_background: Option<String>,

crates/theme/src/default_colors.rs 🔗

@@ -175,6 +175,7 @@ impl ThemeColors {
             vim_visual_background: system.transparent,
             vim_visual_line_background: system.transparent,
             vim_visual_block_background: system.transparent,
+            vim_yank_background: neutral().light_alpha().step_3(),
             vim_helix_normal_background: system.transparent,
             vim_helix_select_background: system.transparent,
             vim_normal_foreground: system.transparent,
@@ -320,6 +321,7 @@ impl ThemeColors {
             vim_visual_background: system.transparent,
             vim_visual_line_background: system.transparent,
             vim_visual_block_background: system.transparent,
+            vim_yank_background: neutral().dark_alpha().step_4(),
             vim_helix_normal_background: system.transparent,
             vim_helix_select_background: system.transparent,
             vim_normal_foreground: system.transparent,

crates/theme/src/fallback_themes.rs 🔗

@@ -257,6 +257,7 @@ pub(crate) fn zed_default_dark() -> Theme {
                 vim_visual_background: SystemColors::default().transparent,
                 vim_visual_line_background: SystemColors::default().transparent,
                 vim_visual_block_background: SystemColors::default().transparent,
+                vim_yank_background: hsla(207.8 / 360., 81. / 100., 66. / 100., 0.2),
                 vim_helix_normal_background: SystemColors::default().transparent,
                 vim_helix_select_background: SystemColors::default().transparent,
                 vim_normal_foreground: SystemColors::default().transparent,

crates/theme/src/schema.rs 🔗

@@ -796,6 +796,11 @@ pub fn theme_colors_refinement(
             .vim_visual_block_background
             .as_ref()
             .and_then(|color| try_parse_color(color).ok()),
+        vim_yank_background: this
+            .vim_yank_background
+            .as_ref()
+            .and_then(|color| try_parse_color(color).ok())
+            .or(editor_document_highlight_read_background),
         vim_helix_normal_background: this
             .vim_helix_normal_background
             .as_ref()

crates/theme/src/styles/colors.rs 🔗

@@ -175,6 +175,8 @@ pub struct ThemeColors {
     pub vim_visual_line_background: Hsla,
     /// Background color for Vim Visual Block mode indicator.
     pub vim_visual_block_background: Hsla,
+    /// Background color for Vim yank highlight.
+    pub vim_yank_background: Hsla,
     /// Background color for Vim Helix Normal mode indicator.
     pub vim_helix_normal_background: Hsla,
     /// Background color for Vim Helix Select mode indicator.

crates/theme_importer/src/vscode/converter.rs 🔗

@@ -207,6 +207,7 @@ impl VsCodeThemeConverter {
             terminal_ansi_white: vscode_colors.terminal.ansi_white.clone(),
             terminal_ansi_bright_white: vscode_colors.terminal.ansi_bright_white.clone(),
             link_text_hover: vscode_colors.text_link.active_foreground.clone(),
+            vim_yank_background: vscode_colors.editor.range_highlight_background.clone(),
             ..Default::default()
         })
     }

crates/vim/src/normal/yank.rs 🔗

@@ -228,7 +228,7 @@ impl Vim {
         editor.highlight_background(
             HighlightKey::HighlightOnYank,
             &ranges_to_highlight,
-            |_, colors| colors.colors().editor_document_highlight_read_background,
+            |_, colors| colors.colors().vim_yank_background,
             cx,
         );
         cx.spawn(async move |this, cx| {