mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 12:30:05 +08:00
fix(scrollbar): fix noautocmd bd
close https://github.com/SpaceVim/SpaceVim/issues/4642
This commit is contained in:
parent
fcc564ae25
commit
2c29bd6462
@ -43,6 +43,7 @@ augroup END
|
|||||||
|
|
||||||
let s:scrollbar_bufnr = -1
|
let s:scrollbar_bufnr = -1
|
||||||
let s:scrollbar_winid = -1
|
let s:scrollbar_winid = -1
|
||||||
|
let s:scrollbar_size = -1
|
||||||
|
|
||||||
function! SpaceVim#plugins#scrollbar#usable() abort
|
function! SpaceVim#plugins#scrollbar#usable() abort
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
function! s:fix_size(size) abort
|
function! s:fix_size(size) abort
|
||||||
return max([s:get('min_size'), min([s:get('max_size'), a:size])])
|
return float2nr(max([s:get('min_size'), min([s:get('max_size'), a:size])]))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:create_scrollbar_buffer(size, lines) abort
|
function! s:create_scrollbar_buffer(size, lines) abort
|
||||||
@ -108,11 +109,13 @@ endfunction
|
|||||||
function! SpaceVim#plugins#scrollbar#show() abort
|
function! SpaceVim#plugins#scrollbar#show() abort
|
||||||
let [winnr, bufnr, winid] = [winnr(), bufnr(), win_getid()]
|
let [winnr, bufnr, winid] = [winnr(), bufnr(), win_getid()]
|
||||||
if s:WIN.is_float(winid)
|
if s:WIN.is_float(winid)
|
||||||
|
call SpaceVim#plugins#scrollbar#clear()
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let excluded_filetypes = s:get('excluded_filetypes')
|
let excluded_filetypes = s:get('excluded_filetypes')
|
||||||
if &filetype == '' || index(excluded_filetypes, &filetype) !=# -1
|
if &filetype == '' || index(excluded_filetypes, &filetype) !=# -1
|
||||||
|
call SpaceVim#plugins#scrollbar#clear()
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -125,8 +128,7 @@ function! SpaceVim#plugins#scrollbar#show() abort
|
|||||||
|
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
let curr_line = pos[1]
|
let curr_line = pos[1]
|
||||||
let bar_size = height * height / total
|
let bar_size = s:fix_size(height * height / total)
|
||||||
let bar_size = s:fix_size(bar_size)
|
|
||||||
|
|
||||||
let width = winwidth(winnr)
|
let width = winwidth(winnr)
|
||||||
let col = width - s:get('width') - s:get('right_offset')
|
let col = width - s:get('width') - s:get('right_offset')
|
||||||
@ -137,20 +139,21 @@ function! SpaceVim#plugins#scrollbar#show() abort
|
|||||||
\ 'relative' : 'win',
|
\ 'relative' : 'win',
|
||||||
\ 'win' : winid,
|
\ 'win' : winid,
|
||||||
\ 'width' : s:get('width'),
|
\ 'width' : s:get('width'),
|
||||||
\ 'height' : float2nr(bar_size),
|
\ 'height' : bar_size,
|
||||||
\ 'row' : float2nr(row),
|
\ 'row' : float2nr(row),
|
||||||
\ 'col' : float2nr(col),
|
\ 'col' : float2nr(col),
|
||||||
\ 'focusable' : 0,
|
\ 'focusable' : 0,
|
||||||
\ }
|
\ }
|
||||||
let state = getbufvar(bufnr, 'scrollbar_state')
|
if s:WIN.is_float(s:scrollbar_winid)
|
||||||
if !empty(state) && s:WIN.is_float(s:scrollbar_winid)
|
if bar_size !=# s:scrollbar_size
|
||||||
if state.size !=# bar_size
|
let s:scrollbar_size = bar_size
|
||||||
let bar_lines = s:gen_bar_lines(bar_size)
|
let bar_lines = s:gen_bar_lines(bar_size)
|
||||||
call s:BUF.buf_set_lines(s:scrollbar_bufnr, 0, -1, 0, bar_lines)
|
call s:BUF.buf_set_lines(s:scrollbar_bufnr, 0, -1, 0, bar_lines)
|
||||||
call s:add_highlight(s:scrollbar_bufnr, bar_size)
|
call s:add_highlight(s:scrollbar_bufnr, bar_size)
|
||||||
endif
|
endif
|
||||||
noautocmd call s:FLOAT.win_config(s:scrollbar_winid, opts)
|
noautocmd call s:FLOAT.win_config(s:scrollbar_winid, opts)
|
||||||
else
|
else
|
||||||
|
let s:scrollbar_size = bar_size
|
||||||
let bar_lines = s:gen_bar_lines(bar_size)
|
let bar_lines = s:gen_bar_lines(bar_size)
|
||||||
let s:scrollbar_bufnr = s:create_scrollbar_buffer(bar_size, bar_lines)
|
let s:scrollbar_bufnr = s:create_scrollbar_buffer(bar_size, bar_lines)
|
||||||
let s:scrollbar_winid = s:FLOAT.open_win(s:scrollbar_bufnr, 0, opts)
|
let s:scrollbar_winid = s:FLOAT.open_win(s:scrollbar_bufnr, 0, opts)
|
||||||
@ -158,11 +161,6 @@ function! SpaceVim#plugins#scrollbar#show() abort
|
|||||||
call setwinvar(win_id2win(s:scrollbar_winid), '&winhighlight', 'Normal:ScrollbarWinHighlight')
|
call setwinvar(win_id2win(s:scrollbar_winid), '&winhighlight', 'Normal:ScrollbarWinHighlight')
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
call setbufvar(bufnr, 'scrollbar_state', {
|
|
||||||
\ 'wind' : s:scrollbar_winid,
|
|
||||||
\ 'bufnr' : s:scrollbar_bufnr,
|
|
||||||
\ 'size' : bar_size,
|
|
||||||
\ })
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" the first argument is buffer number
|
" the first argument is buffer number
|
||||||
|
Loading…
Reference in New Issue
Block a user