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

Update the scrollbar when folding changes #11

Open
wookayin opened this issue Jan 2, 2021 · 9 comments
Open

Update the scrollbar when folding changes #11

wookayin opened this issue Jan 2, 2021 · 9 comments

Comments

@wookayin
Copy link
Contributor

wookayin commented Jan 2, 2021

Great plugin!

Can we have the scrollbar updated when foldlevel is updated (e.g. zM, zR)? For example, when zM is pressed to fold everything (or zR to unfold everything), the scroll bar currently does not get updated.

@wookayin
Copy link
Contributor Author

wookayin commented Jan 2, 2021

Also, the position and the height of a scrollbar is determined by the actual line number (not fully aware of folding). This makes the movement of the scrollbar not uniform and very awkward (it suddenly makes a huge jump) around folded lines.

UPDATE: NVM, sorry. This is configurable as let g:scrollview_mode = 'virtual'.

dstein64 added a commit that referenced this issue Jan 3, 2021
@dstein64
Copy link
Owner

dstein64 commented Jan 3, 2021

Thanks @wookayin!

In addition to the 'virtual' option for scrollview_mode, which you mentioned above, the 'flexible' mode also accounts for folds.

If there were autocmd events that corresponded to fold opening and closing, the plugin would be able to refresh the scrollbars when those events are triggered, but as far as I know there are no such events.

This problem is now documented under :help scrollview-issues (057ec56), along with the following proposed workaround, which could be used with zM and zR (based on your comment above):

  • Remap the problematic fold command key sequences accordingly, depending on the fold commands you use.
nnoremap <silent> zo zo:silent! ScrollViewRefresh<cr>
nnoremap <silent> zc zc:silent! ScrollViewRefresh<cr>

@wookayin
Copy link
Contributor Author

wookayin commented Jan 3, 2021

Thanks. We would need an autocmd event for fold updates for this. As a side note, how about providing <Plug> mappings to make custom keymaps much easier?

@dstein64
Copy link
Owner

dstein64 commented Jan 3, 2021

"As a side note, how about providing mappings to make custom keymaps much easier?"

My interpretation is that the request is so that something like:

nnoremap <silent> zM zM:silent! ScrollViewRefresh<cr>

can be replaced with:

nmap <silent> zM zM<Plug>ScrollViewRefresh

(where I changed nnoremap to nmap, since a recursive mapping is required to expand <Plug>ScrollViewRefresh)

That example would have zM on the right-hand-side, so this would presumably cause an infinite recursion, as the right-hand-side includes the left-hand-side. However, in my experiments there is no infinite recursion, for reasons that aren't clear to me (my expectation is that zM on the right-hand-side would infinitely expand, since the mapping is recursive). I didn't see anything in Vim's documentation on any special-case handling that would prevent an infinite recursion in this type of scenario (e.g., some handling to prevent expansion if the right-hand-side begins with the left-hand-side).

@wookayin, can you provide more details on the usage you are thinking of?

@dstein64
Copy link
Owner

dstein64 commented Jan 5, 2021

@wookayin, I've added the following <Plug> mappings (64de102). Thanks for the idea!

Left-hand-side Right-hand-side
<Plug>(ScrollViewDisable) <cmd>ScrollViewDisable<cr>
<Plug>(ScrollViewEnable) <cmd>ScrollViewEnable<cr>
<Plug>(ScrollViewRefresh) <cmd>ScrollViewRefresh<cr>

Instead of:

nnoremap <silent> zM zM:silent! ScrollViewRefresh<cr>

it's now possible to use:

nmap zM zM<Plug>(ScrollViewRefresh)

My earlier confusion about why this doesn't result in an infinite recursion was resolved by an answer to a question I asked on vi.stackexchange.com. As documented in :help recursive_mapping, there is an exception to recursive expansion when the right-hand-side starts with the left-hand-side.

@wookayin
Copy link
Contributor Author

wookayin commented Jan 6, 2021

Thank you @dstein64! That was exactly I was figuring. For now, I will need to use this keymap-based workaround to trigger the refresh command for folding-related actions.

@wookayin
Copy link
Contributor Author

wookayin commented Jan 8, 2021

Upstream neovim issue for "fold" update events: neovim/neovim#8538

@dstein64
Copy link
Owner

As of 79797a0, an assortment of workarounds are automatically applied, including refreshing the scrollbars after z fold commands (currently excluding zf in normal mode). This doesn't fully address the issue, as : fold commands (e.g., :fold) and zf in normal mode could still lead to the scrollbars being out-of-sync.

The workarounds can be disabled with let g:scrollview_auto_workarounds = 0.

@dstein64
Copy link
Owner

"This doesn't fully address the issue, as : fold commands (e.g., :fold) and zf in normal mode could still lead to the scrollbars being out-of-sync."

Scrollbars are now refreshed after zf is used in normal mode.

: fold commands will still result in scrollbars temporarily out-of-sync (until the next refresh).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants