Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neovim incsearch highlighting tracking issue #30

Closed
gelguy opened this issue Mar 17, 2021 · 13 comments · Fixed by #65
Closed

Neovim incsearch highlighting tracking issue #30

gelguy opened this issue Mar 17, 2021 · 13 comments · Fixed by #65
Labels
bug Something isn't working neovim

Comments

@gelguy
Copy link
Owner

gelguy commented Mar 17, 2021

incsearch highlighting disappears or is sometimes wrong

  • [All versions] Occurs when using wilder#popupmenu_renderer() when searching
  • [Neovim 0.5] Occurs for both wilder#popupmenu_renderer() and wilder#wildmenu_renderer() when searching and the current window view changes (e.g. moves due to incsearch)

See neovim/neovim#14064
See neovim/neovim#12495 (outdated)

A workaround is to use wilder#wildmenu_renderer({'mode': 'statusline'}) for searching.

Update: the statusline workaround doesn't work for Neovim 0.6 nightly.

@gelguy gelguy added the bug Something isn't working label Mar 17, 2021
Gelio added a commit to Gelio/ubuntu-dotfiles that referenced this issue Aug 2, 2021
A workaround for the incsearch not working with wilder.nvim
See gelguy/wilder.nvim#30
@Racle
Copy link

Racle commented Aug 3, 2021

Changing mode doesn't work if you're using also scrollbar plugin (I'm using dstein64/nvim-scrollview and Neovim 0.5).

If file fits to screen, search highlighting works as intended (there is no scrollbar). If file is large and scrollbar becomes visible, wilder will break incsearch highlight.

Quickly way to test this out is to install scrollview and wilder, enable incsearch and try with small and large file.

@gelguy
Copy link
Owner Author

gelguy commented Aug 3, 2021

The underlying root cause for the case with the scrollbar plugin is the same (neovim/neovim#14064) .

An oversimplified explanation: when redrawing windows, highlights are invalidated in some cases. If the viewport does not change too much, the rendering doesn't invalidate the window so the highlights are kept. However, if the viewport changes too much, or if there is a floating window overlaying the window, the highlights are invalidated.

Edit: I've found a workaround for the nvim-scrollview. Note that it has to rebind / which may conflict with some other plugins.

nnoremap / :call WilderStart()<CR>

function! WilderStart()
  call wilder#start_from_normal_mode()
  ScrollViewDisable
  call feedkeys('/', 'n')
endfunction

autocmd CmdlineLeave * ScrollViewEnable

@tzachar
Copy link

tzachar commented Aug 10, 2021

I don't think this is related to nvim-scrollview. I encountered the same behavior, and am not using that plugin.
The problem usually arises when incsearch is enabled and searching for something not in the current viewport.
As you can see in the attached screen grab, for some reason the search reverts back to the previous searched for item on each key stroke.
wilder

b.t.w, I am using neovim nightly

@gelguy
Copy link
Owner Author

gelguy commented Aug 10, 2021

I updated the original issue just yesterday - the statusline workaround does not work for Neovim 0.6 nightly.

Unfortunately I don't have another workaround for this.

@tzachar
Copy link

tzachar commented Aug 10, 2021

10x. Added a confirmation on the nvim bug you opened.
Any idea what is the cause?

@gelguy
Copy link
Owner Author

gelguy commented Aug 10, 2021

I bisected to the problematic commit in the issue mentioned above (neovim/neovim#14064).

In general, Neovim/Vim doesn't like it when redraw is called in the cmdline. The incsearch highlighting is a "temporary" highlight, and it gets invalidated when redrawing in certain cases e.g. the viewport moves or there is a floating/popup window over the buffer.

@tzachar
Copy link

tzachar commented Aug 10, 2021

Then maybe the solution would be to update incsearch proactively after calling redraw? or not call redraw at all?

@gelguy
Copy link
Owner Author

gelguy commented Aug 10, 2021

I've tried many workarounds, but none work so far. Fixing the code in Neovim seems to be the best option.

@gelguy
Copy link
Owner Author

gelguy commented Aug 10, 2021

I've found another workaround 😄.

Could you help verify if the latest master fixes the issue? It should be fixed for all renderers and all Neovim versions.

@Gelio
Copy link

Gelio commented Aug 10, 2021

Yay 🎉 I'm using Neovim nightly and the issue seems to indeed be fixed. I've tested with both wildmenu_renderer and popupmenu_renderer and in both cases the incsearch highlight is stable 😄

Thanks for fixing it!

@Frederick888
Copy link

Frederick888 commented Aug 10, 2021

was being stupid... anyone who gets here pls ignore this comment...


Hate to be that guy but there's still a minor issue for me...

I'm using neovim 0.5.0 and when the first search hit is not in the view before starting searching, the highlights flicker sometimes:

The minimal vimrc I used:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath

" vim-plug
call plug#begin()
Plug 'gelguy/wilder.nvim'
call plug#end()

set incsearch

" wilder.nvim
call wilder#enable_cmdline_enter()
set wildcharm=<Tab>
cmap <expr> <Tab> wilder#in_context() ? wilder#next() : "\<Tab>"
cmap <expr> <S-Tab> wilder#in_context() ? wilder#previous() : "\<S-Tab>"
cmap <expr> <C-n> wilder#in_context() ? wilder#next() : "\<C-n>"
cmap <expr> <C-p> wilder#in_context() ? wilder#previous() : "\<C-p>"
call wilder#set_option('modes', ['/', '?', ':'])
call wilder#set_option('pipeline', [
      \   wilder#branch(
      \     [
      \       wilder#check({_, x -> empty(x)}),
      \       wilder#history(),
      \       wilder#result({
      \         'draw': [{_, x -> '' . x}],
      \         }),
      \     ],
      \     wilder#cmdline_pipeline(),
      \     wilder#search_pipeline(),
      \   ),
      \ ])
if has('nvim')
  call wilder#set_option('renderer', wilder#renderer_mux({
        \ ':': wilder#popupmenu_renderer({
        \       'highlighter': wilder#basic_highlighter(),
        \       'left': [
        \         wilder#popupmenu_devicons(),
        \         ],
        \       'right': [
        \         ' ',
        \         wilder#popupmenu_scrollbar(),
        \         ],
        \       }),
        \ '/': wilder#wildmenu_renderer({
        \       'highlighter': wilder#basic_highlighter(),
        \       }),
        \ '?': wilder#wildmenu_renderer({
        \       'highlighter': wilder#basic_highlighter(),
        \       }),
        \ }))
else
  call wilder#set_option('renderer', wilder#wildmenu_renderer({
        \ 'highlighter': wilder#basic_highlighter(),
        \ }))
endif

" vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=2 smarttab:

@Frederick888
Copy link

Wait... I'm so sorry... I played around with the files locally and there were conflicts when git pull so my wilder.nvim wasn't really up-to-date (face palm...)

Just updated and now the issue is gone. Thank you very much for the fix!

@tzachar
Copy link

tzachar commented Aug 10, 2021

#65 fixes the issue for me.
10x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working neovim
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants