dstein64 / nvim-scrollview

A Neovim plugin that displays interactive vertical scrollbars and signs.
MIT License
517 stars 9 forks source link

Wrong sign background color for floating windows that use nvim_win_set_hl_ns #105

Closed dstein64 closed 9 months ago

dstein64 commented 11 months ago

For floating windows that use nvim_win_set_hl_ns, signs will have the wrong background color.

To address, code will have to be added below the following lines:

https://github.com/dstein64/nvim-scrollview/blob/fca123ab14c72735e37a3cbdd52baa082c7f9def/lua/scrollview.lua#L1485-L1504

The code should check if nvim_win_set_hl_ns has been used on the base window and if so, extract the highlight info for Normal on that window. It may be insufficient to use winhighlight for the sign window (if the highlight used for the base window is not a link, but rather a newly defined highlight specification). It may be necessary to use nvim_win_set_hl_ns on the sign window.

Currently it's not possible to check if nvim_win_set_hl_ns has been used on the base window. https://github.com/neovim/neovim/issues/24309

The following code can be used to reproduce the issue (be sure to add enough lines to the new floating window so a scrollbar and signs show). The cursor sign will have the wrong background color. The problem is not present when using 'winhighlight' (the approach that's commented out).

let buf = nvim_create_buf(v:false, v:true)
let popup = nvim_open_win(buf, 0, {
      \   'relative':  'editor',
      \   'row':       25,
      \   'col':       5,
      \   'width':     20,
      \   'height':    10,
      \   'focusable': v:true,
      \   'style':     'minimal',
      \   'border':    'single',
      \ })
let g:scrollview_floating_windows = v:true

" The following works
"call nvim_win_set_option(popup, 'winhighlight', 'Normal:DiffAdd')

" The following does not work
let ns = nvim_create_namespace('')
call nvim_set_hl(ns, 'Normal', { 'link': 'DiffAdd' })
call nvim_win_set_hl_ns(popup, ns)

Screenshot

(the background color of the cursor sign should be blue, not pink)