From c3edadb4dd21019aeb6d6dc91d5537ce48227d2a Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Sun, 28 Jul 2024 16:45:09 +0100 Subject: [PATCH] Fix diff highlight tweaks Currently the HunkDiffAddAsDelete expects the `bg` property of the DiffDelete highlight group to be present which isn't true for all colorschemes. This updates the highlight group mapping to take all properties from the DiffDelete hl group and map them to hex with proper presence checks. Fixes #8 --- lua/hunk/api/highlights.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lua/hunk/api/highlights.lua b/lua/hunk/api/highlights.lua index 86f9466..a833f5e 100644 --- a/lua/hunk/api/highlights.lua +++ b/lua/hunk/api/highlights.lua @@ -6,15 +6,28 @@ function M.set_win_hl(winid, highlights) }) end +local function color_as_hex(color) + if not color then + return + end + return string.format("#%06x", color) +end + function M.define_highlights() local diff_delete_highlight = vim.api.nvim_get_hl(0, { name = "DiffDelete", link = true, }) - vim.api.nvim_set_hl(0, "HunkDiffAddAsDelete", { - bg = string.format("#%06x", diff_delete_highlight.bg), - }) + vim.api.nvim_set_hl( + 0, + "HunkDiffAddAsDelete", + vim.tbl_deep_extend("force", diff_delete_highlight, { + bg = color_as_hex(diff_delete_highlight.bg), + fg = color_as_hex(diff_delete_highlight.fg), + sp = color_as_hex(diff_delete_highlight.sp), + }) + ) vim.api.nvim_set_hl(0, "HunkDiffDeleteDim", { default = true,