From 1837b2ee39f6e52333ef0a14de4a833b231d7501 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Thu, 15 Mar 2018 15:37:15 +0000 Subject: [PATCH] Use the size of the seperators to get the tabline's remaining space --- autoload/airline/extensions/tabline/tabs.vim | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/autoload/airline/extensions/tabline/tabs.vim b/autoload/airline/extensions/tabline/tabs.vim index 80a8a0a..c822e1d 100644 --- a/autoload/airline/extensions/tabline/tabs.vim +++ b/autoload/airline/extensions/tabline/tabs.vim @@ -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