From 2dc46a1c196d632a1ddf572e221bf9eba0c083fa Mon Sep 17 00:00:00 2001 From: Mark Woods Date: Tue, 22 Apr 2025 13:14:37 +0100 Subject: [PATCH] Handle only bg or fg set when resolving cursor hl The previous code to resolve the cursor highlight didn't allow for only the background or foreground to be set, i.e. only one of guifg & guibg. This was done intentionally to keep the code simple, on the assumption that only setting either background or foreground was so rare that it didn't warrant the additional complexity, but it seems that assumption was misguided, while it is unusual, it's not rare enough to ignore. See https://github.com/Donaldttt/fuzzyy/pull/84 for background Thanks @casr for reporting this and researching in some detail :-) --- autoload/fuzzyy/utils/popup.vim | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/autoload/fuzzyy/utils/popup.vim b/autoload/fuzzyy/utils/popup.vim index 5a50b63..c27508d 100644 --- a/autoload/fuzzyy/utils/popup.vim +++ b/autoload/fuzzyy/utils/popup.vim @@ -64,19 +64,23 @@ def ResolveCursor() gui: { 'reverse': true }, } var attrs = hlget('Cursor', true)->get(0, {}) - if !attrs->get('guifg') || !attrs->get('guibg') + if !attrs->get('guifg') && !attrs->get('guibg') hlset([fallback]) return endif var special = ['NONE', 'bg', 'fg', 'background', 'foreground'] - var guifg = attrs->get('guifg') - var guibg = attrs->get('guibg') - if index(special, guifg) != -1 || index(special, guibg) != -1 - hlset([fallback]) + var guifg = attrs->get('guifg', 'NONE') + var guibg = attrs->get('guibg', 'NONE') + if has('gui') + hlset([{name: 'fuzzyyCursor', guifg: guifg, guibg: guibg}]) return endif - var ctermfg = attrs->get('ctermfg', string(colors.TermColor(guifg))) - var ctermbg = attrs->get('ctermbg', string(colors.TermColor(guibg))) + var ctermfg = attrs->get('ctermfg', + index(special, guifg) != -1 ? guifg : string(colors.TermColor(guifg)) + ) + var ctermbg = attrs->get('ctermbg', + index(special, guibg) != -1 ? guibg : string(colors.TermColor(guibg)) + ) try hlset([{ name: 'fuzzyyCursor', @@ -85,6 +89,9 @@ def ResolveCursor() ctermfg: ctermfg, ctermbg: ctermbg }]) + catch /\v:(E419|E420|E453):/ + # foreground and/or background not known and used as ctermfg or ctermbg + hlset([fallback]) catch Warn('Fuzzyy: failed to resolve cursor highlight: ' .. v:exception) hlset([fallback])