From 8510162408944a1edb85e58ba89513a5515bbc46 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Mon, 8 Jan 2024 18:27:25 +0100 Subject: [PATCH] fix(moonfly): override part of highlights instead of replacing them --- lua/plugins/moonfly.lua | 19 ++++++++++++++----- lua/utils.lua | 13 +++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lua/plugins/moonfly.lua b/lua/plugins/moonfly.lua index aa56cbf..22e2fe0 100644 --- a/lua/plugins/moonfly.lua +++ b/lua/plugins/moonfly.lua @@ -1,18 +1,27 @@ -- https://github.com/bluz71/vim-moonfly-colors +local utils = require("utils") + +local function override_hl(hl_name, opts) + local hl = vim.api.nvim_get_hl(0, { name = hl_name, }) + utils.update_table(hl, opts) + vim.api.nvim_set_hl(0, hl_name, hl) +end + local function setup() vim.g.moonflyNormalFloat = true vim.g.moonflyCursorColor = true vim.g.moonflyWinSeparator = 2 - local custom_highlight = vim.api.nvim_create_augroup("CustomMoonflyHighlight", {}) + local custom_highlight = vim.api.nvim_create_augroup( + "CustomMoonflyHighlight", {}) vim.api.nvim_create_autocmd("ColorScheme", { pattern = "moonfly", callback = function () - vim.api.nvim_set_hl(0, "DiffAdd", { bg = "#364143" }) - vim.api.nvim_set_hl(0, "DiffText", { bg = "#3e4b6b" }) - vim.api.nvim_set_hl(0, "DiffChange", { bg = "#25293c" }) - vim.api.nvim_set_hl(0, "DiffDelete", { bg = "#443244" }) + override_hl("DiffAdd", { bg = "#364143", }) + override_hl("DiffText", { bg = "#3e4b6b", }) + override_hl("DiffChange", { bg = "#25293c", }) + override_hl("DiffDelete", { bg = "#443244", }) end, group = custom_highlight, }) diff --git a/lua/utils.lua b/lua/utils.lua index b4918c6..9681e2d 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -98,4 +98,17 @@ function M.try_require(module, err_title, on_success) M.err(resp, err_title) end +--- Update table t1 with values in t2. +--- @param table table: The table to update +--- @param values table: The table with new values +function M.update_table(table, values) + for k, v in pairs(values) do + if type(v) == "table" and type(table[k] or false) == "table" then + M.update_table(table[k], values[k]) + else + table[k] = v + end + end +end + return M