From 904f141366533d00e059b6c455516856d006a3a4 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 19:37:33 -0500 Subject: [PATCH] fix(highlight): replace hardcoded theme-specific color fallbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: fallback hex values for `Normal.bg`, `DiffAdd.bg`, etc. in `compute_highlight_groups` were hardcoded to catppuccin mocha colors (`0x1e1e2e`, `0x2e4a3a`, `0x4a2e3a`, etc.), producing visibly wrong highlight groups for users on any other colorscheme when `Normal` has no background (transparent terminals or early startup). Solution: replace all hardcoded fallbacks with `vim.o.background`-aware neutral values — dark mode gets near-black/grey, light mode gets near-white/dark-grey — so the fallback path is theme-agnostic. --- lua/diffs/init.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lua/diffs/init.lua b/lua/diffs/init.lua index 77f521a..a176d80 100644 --- a/lua/diffs/init.lua +++ b/lua/diffs/init.lua @@ -470,11 +470,12 @@ local function compute_highlight_groups() local diff_added = resolve_hl('diffAdded') local diff_removed = resolve_hl('diffRemoved') - local bg = normal.bg or 0x1e1e2e - local add_bg = diff_add.bg or 0x2e4a3a - local del_bg = diff_delete.bg or 0x4a2e3a - local add_fg = diff_added.fg or diff_add.fg or 0x80c080 - local del_fg = diff_removed.fg or diff_delete.fg or 0xc08080 + local dark = vim.o.background ~= 'light' + local bg = normal.bg or (dark and 0x1a1a1a or 0xf0f0f0) + local add_bg = diff_add.bg or (dark and 0x1a3a1a or 0xd0ffd0) + local del_bg = diff_delete.bg or (dark and 0x3a1a1a or 0xffd0d0) + 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) local blended_add = blend_color(add_bg, bg, 0.4) local blended_del = blend_color(del_bg, bg, 0.4) @@ -483,7 +484,7 @@ local function compute_highlight_groups() local blended_add_text = blend_color(add_fg, bg, alpha) local blended_del_text = blend_color(del_fg, bg, alpha) - vim.api.nvim_set_hl(0, 'DiffsClear', { default = true, fg = normal.fg or 0xc0c0c0, bg = bg }) + vim.api.nvim_set_hl(0, 'DiffsClear', { default = true, fg = normal.fg or (dark and 0xcccccc or 0x333333), bg = bg }) vim.api.nvim_set_hl(0, 'DiffsAdd', { default = true, bg = blended_add }) vim.api.nvim_set_hl(0, 'DiffsDelete', { default = true, bg = blended_del }) vim.api.nvim_set_hl(0, 'DiffsAddNr', { default = true, fg = blended_add_text, bg = blended_add })