Skip to content

Commit c3edadb

Browse files
committed
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
1 parent e316a3e commit c3edadb

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

lua/hunk/api/highlights.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@ function M.set_win_hl(winid, highlights)
66
})
77
end
88

9+
local function color_as_hex(color)
10+
if not color then
11+
return
12+
end
13+
return string.format("#%06x", color)
14+
end
15+
916
function M.define_highlights()
1017
local diff_delete_highlight = vim.api.nvim_get_hl(0, {
1118
name = "DiffDelete",
1219
link = true,
1320
})
1421

15-
vim.api.nvim_set_hl(0, "HunkDiffAddAsDelete", {
16-
bg = string.format("#%06x", diff_delete_highlight.bg),
17-
})
22+
vim.api.nvim_set_hl(
23+
0,
24+
"HunkDiffAddAsDelete",
25+
vim.tbl_deep_extend("force", diff_delete_highlight, {
26+
bg = color_as_hex(diff_delete_highlight.bg),
27+
fg = color_as_hex(diff_delete_highlight.fg),
28+
sp = color_as_hex(diff_delete_highlight.sp),
29+
})
30+
)
1831

1932
vim.api.nvim_set_hl(0, "HunkDiffDeleteDim", {
2033
default = true,

0 commit comments

Comments
 (0)