diff --git a/doc/diffs.nvim.txt b/doc/diffs.nvim.txt index cfcd1b6..79f34b7 100644 --- a/doc/diffs.nvim.txt +++ b/doc/diffs.nvim.txt @@ -758,6 +758,13 @@ character-level groups blend at 60% for more contrast. Line-number groups combine both: background from the line-level blend, foreground from the character-level blend. +Note: highlight groups are computed when the first diff buffer is attached, +so your colorscheme must be loaded before any diff buffer opens. If `Normal` +has no background at that point (colorscheme loaded too late, or transparent +terminal), diffs.nvim schedules one deferred retry via |vim.schedule()| to +recompute once the event loop settles. To avoid relying on this, ensure your +colorscheme plugin has `priority = 1000` and `lazy = false`. + Fugitive unified diff highlights: ~ *DiffsAdd* DiffsAdd Background for `+` lines. Derived by blending diff --git a/lua/diffs/init.lua b/lua/diffs/init.lua index a176d80..a68b7ee 100644 --- a/lua/diffs/init.lua +++ b/lua/diffs/init.lua @@ -162,6 +162,7 @@ local default_config = { local config = vim.deepcopy(default_config) local initialized = false +local hl_retry_pending = false ---@diagnostic disable-next-line: missing-fields local fast_hl_opts = {} ---@type diffs.HunkOpts @@ -477,6 +478,17 @@ local function compute_highlight_groups() local add_fg = diff_added.fg or diff_add.fg or (dark and 0x80d080 or 0x206020) local del_fg = diff_removed.fg or diff_delete.fg or (dark and 0xd08080 or 0x802020) + if not normal.bg and not hl_retry_pending then + hl_retry_pending = true + vim.schedule(function() + hl_retry_pending = false + compute_highlight_groups() + for bufnr, _ in pairs(attached_buffers) do + invalidate_cache(bufnr) + end + end) + end + local blended_add = blend_color(add_bg, bg, 0.4) local blended_del = blend_color(del_bg, bg, 0.4)