Xuyuanp / scrollbar.nvim

scrollbar for neovim
Apache License 2.0
269 stars 10 forks source link

<C-w>o removes the scrollbar and Neovim cannot show it again #12

Closed delphinus closed 4 years ago

delphinus commented 4 years ago

When I type <C-w>o to close all windows other than the focused one, the scrollbar disappears and Neovim shows an error with show().

:lua require('scrollbar').show()
E5108: Error executing lua ...epos/github.com/Xuyuanp/scrollbar.nvim/lua/scrollbar.lua:146: Invalid window id: 1021

This is because b:scrollbar_state.winnr indicates a floating window that is already closed by <C-w>o.

:unlet b:scrollbar_state
:lua require('scrollbar').show()

I can show the scrollbar again by codes above, but it is annoying a bit. So,

  1. Can the scrollbar stay still when <C-w>o pressed?
  2. Can show() clear b:scrollbar_state if winnr indicates an invalid ID?
Xuyuanp commented 4 years ago

I pushed a fixed. please take a look.

delphinus commented 4 years ago

Thx! I found no error occurs on show(). The scrollbar still disappears after <C-w>o, but it shows again when CursorMoved.

I wrote a workaround on my config.

https://github.com/delphinus/dotfiles/blob/b1e6834941a1c065ba31467b6e2b0ebd3e62db3f/.vim/rc/dein/default.toml#L801-L806

  function! s:only_and_show() abort
    only
    silent! lua require('scrollbar').show()
  endfunction
  map <C-w>o :silent call <SID>only_and_show()<CR>

With this, <C-w>o does not remove the scrollbar (:only still removes it).

Xuyuanp commented 4 years ago

Great tricks.