Last active
December 24, 2020 03:13
-
-
Save dstein64/ddf3f44a504c90e5338f2a5ba2bd3605 to your computer and use it in GitHub Desktop.
An example script for hiding nvim-scrollview scrollbars shortly after scrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" The amount of time, in milliseconds, until scrollbar hides after scrolling. | |
let s:hide_delay = 800 | |
" Time of the last WinScrolled event | |
let s:scroll_time = 0 | |
" Keep track of pending updates. Ignore updates if there are already pending | |
" updates, to prevent lag. | |
let s:pending = 0 | |
function! s:RelativeTime() abort | |
" Add 0.5 so conversion rounds. | |
return float2nr((reltimefloat(reltime()) * 1000) + 0.5) | |
endfunction | |
function! s:UpdateScrollView() abort | |
if !exists(':ScrollViewDisable') || !exists(':ScrollViewEnable') | |
return | |
endif | |
let s:pending -= 1 | |
if s:pending ># 0 | return | endif | |
" Amount of time since last scroll event | |
let l:elapsed = s:RelativeTime() - s:scroll_time | |
if l:elapsed ># s:hide_delay | |
ScrollViewDisable | |
return | |
endif | |
ScrollViewEnable | |
let s:pending += 1 | |
call timer_start(s:hide_delay - l:elapsed, | |
\ {-> execute('call s:UpdateScrollView()')}) | |
endfunction | |
augroup scrollview_hide | |
autocmd! | |
autocmd WinScrolled * :let s:scroll_time = s:RelativeTime() | |
autocmd WinScrolled * :let s:pending += 1 | |
autocmd WinScrolled * :call s:UpdateScrollView() | |
augroup END | |
" Only show scrollbar in current window. | |
let g:scrollview_current_only = 1 | |
" Disable scrollview on startup. | |
let g:scrollview_on_startup = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment