Pass the available space for tabs as an argument to |get_visible_tabs|

This commit is contained in:
mrmr1993 2018-03-12 18:12:08 +00:00
parent cf47d63f71
commit 2711c73a47

View File

@ -25,7 +25,7 @@ function! airline#extensions#tabline#tabs#invalidate()
let s:current_bufnr = -1 let s:current_bufnr = -1
endfunction endfunction
function! s:get_visible_tabs() function! s:get_visible_tabs(width)
let tablist = range(1, tabpagenr('$')) let tablist = range(1, tabpagenr('$'))
let curbuf = bufnr('%') let curbuf = bufnr('%')
@ -48,13 +48,12 @@ function! s:get_visible_tabs()
" only show current and surrounding tabs if there are too many tabs " only show current and surrounding tabs if there are too many tabs
let position = index(tablist, curbuf) let position = index(tablist, curbuf)
let vimwidth = &columns if total_width > a:width && position > -1
if total_width > vimwidth && position > -1
let tab_count = len(tablist) let tab_count = len(tablist)
" determine how many tabs to show based on the longest tab width, " determine how many tabs to show based on the longest tab width,
" use one on the right side and put the rest on the left " use one on the right side and put the rest on the left
let tab_max = vimwidth / max_width let tab_max = a:width / max_width
let tab_right = 1 let tab_right = 1
let tab_left = max([0, tab_max - tab_right]) let tab_left = max([0, tab_max - tab_right])
@ -103,7 +102,7 @@ function! airline#extensions#tabline#tabs#get()
let b = airline#extensions#tabline#new_builder() let b = airline#extensions#tabline#new_builder()
call airline#extensions#tabline#add_label(b, 'tabs') call airline#extensions#tabline#add_label(b, 'tabs')
for i in s:get_visible_tabs() for i in s:get_visible_tabs(&columns)
if i < 0 if i < 0
call b.add_raw('%#airline_tab#...') call b.add_raw('%#airline_tab#...')
continue continue