Use the size of the seperators to get the tabline's remaining space

This commit is contained in:
mrmr1993 2018-03-15 15:37:15 +00:00
parent d3ec54d42e
commit 1837b2ee39

View File

@ -103,12 +103,20 @@ function! airline#extensions#tabline#tabs#get()
let right_position = tabs_position + 1
let remaining_space = &columns - s:strchars(s:evaluate_tabline(b.build()))
let left_sep_size = s:strchars(s:evaluate_tabline(b._context.left_sep))
let left_alt_sep_size = s:strchars(s:evaluate_tabline(b._context.left_alt_sep))
let skipped_tabs_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
let remaining_space -= 2 * s:strchars(s:evaluate_tabline(skipped_tabs_marker))
let skipped_tabs_marker_size = s:strchars(s:evaluate_tabline(skipped_tabs_marker))
" The left marker will have left_alt_sep, and the right will have left_sep.
let remaining_space -= 2 * skipped_tabs_marker_size + left_sep_size + left_alt_sep_size
" Add the current tab
let tab_title = s:get_title(tab_nr_type, curtab)
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + 1
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title))
" There are always two left_seps (either side of the selected tab) and all
" other seperators are left_alt_seps.
let remaining_space -= 2 * left_sep_size - left_alt_sep_size
let group = 'airline_tabsel'
if g:airline_detect_modified
for bi in tabpagebuflist(curtab)
@ -128,7 +136,7 @@ function! airline#extensions#tabline#tabs#get()
" Add the tab to the right
if right_tab <= num_tabs
let tab_title = s:get_title(tab_nr_type, right_tab)
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + 1
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
call b.insert_section('airline_tab', tab_title, right_position)
let right_position += 1
let right_tab += 1
@ -137,7 +145,7 @@ function! airline#extensions#tabline#tabs#get()
while remaining_space > 0
if left_tab > 0
let tab_title = s:get_title(tab_nr_type, left_tab)
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + 1
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
if remaining_space >= 0
call b.insert_section('airline_tab', tab_title, left_position)
let right_position += 1
@ -145,7 +153,7 @@ function! airline#extensions#tabline#tabs#get()
endif
elseif right_tab <= num_tabs
let tab_title = s:get_title(tab_nr_type, right_tab)
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + 1
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
if remaining_space >= 0
call b.insert_section('airline_tab', tab_title, right_position)
let right_position += 1