From 3da14f892fe2c05d5a0c50335dcf64f1eea81db4 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Sat, 7 Mar 2026 19:46:17 +0100 Subject: [PATCH] Fix nvim transparency to preserve foreground colors (#4844) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix nvim transparency to preserve foreground colors The old approach used `vim.api.nvim_set_hl(0, name, { bg = "none" })` which replaces the entire highlight definition, wiping out foreground and other attributes. This breaks snacks.nvim's GitHub integration (gh_pr/gh_issue pickers) which reads the foreground color from Normal and NormalFloat at module load time, gets nil, and crashes in Snacks.util.blend(). The fix uses nvim_get_hl to fetch existing attributes first, removes only bg, then sets the highlight back — preserving all other attributes. * Drop fallback that reintroduces the highlight-wiping bug If nvim_get_hl fails for a group, skip it rather than falling back to the old { bg = "none" } approach that clears all attributes. --- migrations/1772389838.sh | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 migrations/1772389838.sh diff --git a/migrations/1772389838.sh b/migrations/1772389838.sh new file mode 100644 index 00000000..8a98a3ea --- /dev/null +++ b/migrations/1772389838.sh @@ -0,0 +1,67 @@ +echo "Fix nvim transparency to preserve highlight foreground colors" + +TRANSPARENCY_FILE="$HOME/.config/nvim/plugin/after/transparency.lua" + +if [[ -f "$TRANSPARENCY_FILE" ]]; then + cat > "$TRANSPARENCY_FILE" << 'EOF' +-- Make highlight groups transparent while preserving their other attributes +local function make_transparent(name) + local ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = name, link = false }) + if ok then + hl.bg = nil + vim.api.nvim_set_hl(0, name, hl) + end +end + +local groups = { + -- transparent background + "Normal", + "NormalFloat", + "FloatBorder", + "Pmenu", + "Terminal", + "EndOfBuffer", + "FoldColumn", + "Folded", + "SignColumn", + "LineNr", + "CursorLineNr", + "NormalNC", + "WhichKeyFloat", + "TelescopeBorder", + "TelescopeNormal", + "TelescopePromptBorder", + "TelescopePromptTitle", + -- neotree + "NeoTreeNormal", + "NeoTreeNormalNC", + "NeoTreeVertSplit", + "NeoTreeWinSeparator", + "NeoTreeEndOfBuffer", + -- nvim-tree + "NvimTreeNormal", + "NvimTreeVertSplit", + "NvimTreeEndOfBuffer", + -- notify + "NotifyINFOBody", + "NotifyERRORBody", + "NotifyWARNBody", + "NotifyTRACEBody", + "NotifyDEBUGBody", + "NotifyINFOTitle", + "NotifyERRORTitle", + "NotifyWARNTitle", + "NotifyTRACETitle", + "NotifyDEBUGTitle", + "NotifyINFOBorder", + "NotifyERRORBorder", + "NotifyWARNBorder", + "NotifyTRACEBorder", + "NotifyDEBUGBorder", +} + +for _, name in ipairs(groups) do + make_transparent(name) +end +EOF +fi