Skip to content

Commit 2dc46a1

Browse files
committed
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 #84 for background Thanks @casr for reporting this and researching in some detail :-)
1 parent f424831 commit 2dc46a1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

autoload/fuzzyy/utils/popup.vim

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ def ResolveCursor()
6464
gui: { 'reverse': true },
6565
}
6666
var attrs = hlget('Cursor', true)->get(0, {})
67-
if !attrs->get('guifg') || !attrs->get('guibg')
67+
if !attrs->get('guifg') && !attrs->get('guibg')
6868
hlset([fallback])
6969
return
7070
endif
7171
var special = ['NONE', 'bg', 'fg', 'background', 'foreground']
72-
var guifg = attrs->get('guifg')
73-
var guibg = attrs->get('guibg')
74-
if index(special, guifg) != -1 || index(special, guibg) != -1
75-
hlset([fallback])
72+
var guifg = attrs->get('guifg', 'NONE')
73+
var guibg = attrs->get('guibg', 'NONE')
74+
if has('gui')
75+
hlset([{name: 'fuzzyyCursor', guifg: guifg, guibg: guibg}])
7676
return
7777
endif
78-
var ctermfg = attrs->get('ctermfg', string(colors.TermColor(guifg)))
79-
var ctermbg = attrs->get('ctermbg', string(colors.TermColor(guibg)))
78+
var ctermfg = attrs->get('ctermfg',
79+
index(special, guifg) != -1 ? guifg : string(colors.TermColor(guifg))
80+
)
81+
var ctermbg = attrs->get('ctermbg',
82+
index(special, guibg) != -1 ? guibg : string(colors.TermColor(guibg))
83+
)
8084
try
8185
hlset([{
8286
name: 'fuzzyyCursor',
@@ -85,6 +89,9 @@ def ResolveCursor()
8589
ctermfg: ctermfg,
8690
ctermbg: ctermbg
8791
}])
92+
catch /\v:(E419|E420|E453):/
93+
# foreground and/or background not known and used as ctermfg or ctermbg
94+
hlset([fallback])
8895
catch
8996
Warn('Fuzzyy: failed to resolve cursor highlight: ' .. v:exception)
9097
hlset([fallback])

0 commit comments

Comments
 (0)