dstein64 / nvim-scrollview

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

Search sign group Incompatible with "auto-nohl" snippet #88

Closed chrisgrieser closed 1 year ago

chrisgrieser commented 1 year ago

This is kind off more a request for support than a bug report, but since a bunch of people have such a "auto-nohl" snippet, it is probably relevant to more people than just me

So I use the following snippet to automatically set :nohl when I am using a non-search key (not n / N etc.) and automatically enable search highlights when I do a search:

vim.on_key(function(char)
    local searchKeys = { "n", "N", "*", "#" }
    local searchConfirmed = (fn.keytrans(char) == "<CR>" and fn.getcmdtype():find("[/?]") ~= nil)
    if not (searchConfirmed or fn.mode() == "n") then return end
    local searchKeyUsed = searchConfirmed or (vim.tbl_contains(searchKeys, fn.keytrans(char)))
    if vim.opt.hlsearch:get() ~= searchKeyUsed then vim.opt.hlsearch = searchKeyUsed end
end, vim.api.nvim_create_namespace("auto_nohl"))

however, when I have nvim-scrollview as well as that snippet active, pressing n results in the highlights (and the search signs in the scrollbar) briefly appearing and than disappearing. I would guess it is because nvim-scrollview presses some key behind the scenes somewhere?

Would it be possible to make this plugin compatible with the auto-nohl snippet or give some advice on how the snippet has to be changed to work together with this plugin?

dstein64 commented 1 year ago

Hi @chrisgrieser. Thanks for reporting the issue.

I'm unable to reproduce the problem. When I launch Neovim configured only with the snippet of code you provided, nvim-scrollview functions as expected.

If you only include that snippet of code in your config (omitting all other configuration code), do you still encounter the issue?

chrisgrieser commented 1 year ago

yes, the issue also occurs with nothing but nvim-scrollview and the snippet in my config :/

here my version information in case it helps? 🤔

macOS 13.3.1 (M1)
neovim 0.9.0 (homebrew)
Neovide 0.10.4 (homebrew)
dstein64 commented 1 year ago

I can now reproduce. I was originally only looking at the scrollbar signs, which still are displayed for me. But I can now see that the search pattern is not highlighted.

dstein64 commented 1 year ago

nvim-scrollview calls :normal! while updating scrollbars, which triggers the vim.on_key function.

I've added a global variable, g:scrollview_refreshing, that gets set to v:true while scrollbars are being refreshed (a0ae5f9, 02d0880).

With that update, a workaround is to have your function ignore keys while scrollview is refreshing.

vim.on_key(function(char)
    if vim.g.scrollview_refreshing then return end
    ...
chrisgrieser commented 1 year ago

thanks! can confirm that this does fix the issue 😊