Skip to content

Commit

Permalink
Fix diff highlight tweaks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
julienvincent committed Jul 28, 2024
1 parent e316a3e commit c3edadb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lua/hunk/api/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c3edadb

Please sign in to comment.