mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-01 20:28:16 +02:00
Fix nvim transparency to preserve foreground colors (#4844)
* 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.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user