[vim/vim] Opacity with undefined bg for popup highlight group result a fully transparent popup (PR #20414)

4 views
Skip to first unread message

Shad

unread,
4:19 PM (4 hours ago) 4:19 PM
to vim/vim, Subscribed

Problem: When using popup with a highlight group without background color set, and opacity set between 1 and 99 the blending fail and the popup is completely transparent.
I'm expecting a fadeout toward the underlying background color.

it occurs when popup highlight or highlights option are set to a group:

  • Normal
  • a group linked to Normal
  • a cleared group
  • a group with no ctermbg and guibg set or set to NONE

Moreover in the case ctermfg and guifg are not set, the underlying text color bleed on the popup text if this one does not have a color attribute (see the $${\color{cyan}OV\color{black}E\color{green}RANDABO\color{black}V\color{pink}E}$$ text in the screenshots)

Before this patch:
opacity-before-patch.png (view on web)

After this patch:
opacity-after-patch.png (view on web)

Since gui and cterm code are separate, I wanted to add similar screendump for gui but it works only for terminal, is there any way to do this kind of test for gvim ?

As the blocs guarded by if (popup_attr > HL_ALL) are not conditional any more, to ease the review on github, I've removed the bloc brackets and reindent in a separate commit.

To test it:
open a vim file containing

" DUMB CODE TO HAVE COLORED TEXT UNDER POPUP
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░ █▓▒░
" 0123456789 abcdef    TODO

highlight grup cterm=underline ctermbg=1 guibg=#00ff00

          let s:uvar = &filetype . 'under' + 1


" ===== END OF DUMB CODE =====
"hi! link Pmenu Normal
function! Custompopup(hlgroup, position, opacity) abort
    let popup_content = [
                    \ '" popup content',
                    \ '" A C E  TODO         █▓▒░ ',
                    \ 'hi p cterm=nocombine ctermbg=1 guibg=#ccc',
                    \ '                  OVERANDABOVE',
                    \ 'let s:pvar = &filetype . "popup" + 1',
                    \ '']
    if (has('nvim'))
        let bufnr = nvim_create_buf(v:false, v:true)
        let opts = {
                    \  'relative': 'win',
                    \  'row': a:position['line'] -1,
                    \  'border': [ '', '' ,'', '', '', '', '', '' ],
                    \  'width': 41,
                    \  'height': 7,
                    \  'fixed': 1,
                    \  'col': a:position['col'] -1,
                    \  'title': 'Opacity ' . a:opacity . '% - Highlight: ' . a:hlgroup,
                    \ }
        call nvim_buf_set_lines(bufnr, 0, -1, v:true, popup_content)
        let winid = nvim_open_win(bufnr, 0, opts)
        call nvim_win_set_option(winid, 'winblend', 100 - a:opacity)
        call nvim_win_set_option(winid, 'filetype', 'vim')
        call nvim_set_option_value('winhl', 'Normal:' . a:hlgroup, {'win': winid})
    else
        let opts = {
                    \  'border': [1, 1, 1, 1],
                    \  'line': a:position['line'],
                    \  'close': 'button',
                    \  'minheight': 7,
                    \  'minwidth': 40,
                    \  'opacity': a:opacity,
                    \  'fixed': 1,
                    \  'col': a:position['col'],
                    \  'highlights': 'Normal:' . a:hlgroup,
                    \  'title': 'Opacity ' . a:opacity . '% - Highlight: ' . a:hlgroup,
                    \ }
        let winid = popup_create(popup_content, opts)
        call setbufvar(winbufnr(winid), '&filetype', 'vim')
        endif
    return winid
endfunction

highlight link LinkedToNormal Normal
highlight clear ClearedGroup
highlight OnlyFg ctermfg=blue guifg=blue
highlight OnlyBg ctermbg=green guibg=green
highlight BgNone ctermfg=red guifg=red ctermbg=NONE guibg=NONE
let popupline = 2
for hlgroup in ['Pmenu', 'Normal', 'LinkedToNormal', 'ClearedGroup', 'OnlyFg', 'OnlyBg', 'BgNone']
    let win1 = Custompopup(hlgroup, {'line': popupline, 'col': 10}, 80)
    let popupline = popupline + 9
endfor

set wildoptions=pum,fuzzy
" to compare popup and pum opacity
if (has('nvim'))
    let pumblend=20
else
    set pumopt=opacity:80
endif

source it:

:source

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/20414

Commit Summary

  • a783d41 No opacity when guibg/ctermgb not set to popup group highlight
  • 1b907b6 remove non conditional anymore blocs and reindent them
  • b05b4a2 add test for popup opacity when bg color of popup highlight group is not set
  • ed326fa add tests for opacity popup with only ctermbg or guibg set
  • 835aa37 update dump
  • c540f55 update dump

File Changes

(18 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20414@github.com>

Foxe Chen

unread,
4:43 PM (4 hours ago) 4:43 PM
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#20414)

Since gui and cterm code are separate, I wanted to add similar screendump for gui but it works only for terminal, is there any way to do this kind of test for gvim ?

You can add CheckGui at the start of the test function. It will skip the test if the Vim being tested is not gvim


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20414/c4606843895@github.com>

Shad

unread,
6:28 PM (2 hours ago) 6:28 PM
to vim/vim, Subscribed
shadowwa left a comment (vim/vim#20414)

You can add CheckGui at the start of the test function. It will skip the test if the Vim being tested is not gvim

I mean, I've started to add in src/testdir/test_gui.vim a test like

func Test_gui_popup_opacity_undefined_popup_highlight()
CheckGui
CheckScreendump
"[…]
call VerifyScreenDump(…

to get an error E117: Unknown function: VerifyScreenDump after that, I realised that VerifyScreenDump was explicitly for terminal use

" Verify that Vim running in terminal buffer "buf" matches the screen dump.

but did not found a similar function for gui use.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20414/c4607495530@github.com>

Foxe Chen

unread,
8:19 PM (5 minutes ago) 8:19 PM
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#20414)

You can add CheckGui at the start of the test function. It will skip the test if the Vim being tested is not gvim

I mean, I've started to add in src/testdir/test_gui.vim a test like

func Test_gui_popup_opacity_undefined_popup_highlight()

CheckGui

CheckScreendump

"[…]

call VerifyScreenDump(…

to get an error E117: Unknown function: VerifyScreenDump after that, I realised that VerifyScreenDump was explicitly for terminal use

" Verify that Vim running in terminal buffer "buf" matches the screen dump.

but did not found a similar function for gui use.

VerifyScreenDump should work in the GUI, it uses the terminal feature, not the terminal Vim is running in. I think the error you are getting is because test_gui.vim doesn't source src/screendump.vim. However you shouldnt be putting the tests in test_gui, just put them in test_popup. The CI will run Vim in the GUI against all the tests anyways


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20414/c4608019908@github.com>

Reply all
Reply to author
Forward
0 new messages