Consider the following snippet:
vim9script
var colors = getcompletion('', 'color', true)
def PopupFilterColor(id: number, key: string): bool
if index(['j', "\<down>", "\<c-n>"], key) != -1
win_execute(id, 'norm j')
var idx = line('.', id)
var scheme = getbufline(winbufnr(id), idx)[0]
exe $'colorscheme {scheme}'
return true
elseif index(['k', "\<Up>", "\<c-p>"], key) != -1
win_execute(id, 'norm k')
var idx = line('.', id)
var scheme = getbufline(winbufnr(id), idx)[0]
exe $'colorscheme {scheme}'
return true
elseif key == "\<esc>"
popup_close(id)
colorscheme blue
return true
endif
return false
enddef
var opts = {
filter: PopupFilterColor
}
popup_menu(colors, opts)
Now, source the script and scroll up and down. You see the colorscheme changes as you move in the popup_menu. Next, hit <esc>
and source the script again.
Now, the hightlight is often lost when you scroll the items displayed in the popup menu.
What am I doing wrong? How to fix it?