Use insert_section for overflow markers in tabline builder

This commit is contained in:
mrmr1993 2018-03-22 16:01:06 +00:00
parent df2f380c9e
commit 4b1913ad13

View File

@ -103,19 +103,33 @@ function! s:prototype.build() dict
let sep_size = s:tabline_evaluated_length(self._context.left_sep) let sep_size = s:tabline_evaluated_length(self._context.left_sep)
let alt_sep_size = s:tabline_evaluated_length(self._context.left_alt_sep) let alt_sep_size = s:tabline_evaluated_length(self._context.left_alt_sep)
let overflow_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
let overflow_marker_size = s:tabline_evaluated_length(overflow_marker)
" Allow space for the markers before we begin filling in titles.
let self._remaining_space -= 2 * overflow_marker_size
let outer_left_group = airline#builder#get_prev_group(self._sections, self._left_position) let outer_left_group = airline#builder#get_prev_group(self._sections, self._left_position)
let outer_right_group = airline#builder#get_next_group(self._sections, self._right_position) let outer_right_group = airline#builder#get_next_group(self._sections, self._right_position)
let overflow_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
let overflow_marker_size = s:tabline_evaluated_length(overflow_marker)
" Allow space for the markers before we begin filling in titles.
if self._left_title > self._first_title
let self._remaining_space -= overflow_marker_size +
\ s:get_separator_change(self.overflow_group, "", outer_left_group, sep_size, alt_sep_size)
endif
if self._left_title < self._last_title
let self._remaining_space -= overflow_marker_size +
\ s:get_separator_change(self.overflow_group, "", outer_right_group, sep_size, alt_sep_size)
endif
" Add the current title " Add the current title
let group = self.get_group(self._left_title) let group = self.get_group(self._left_title)
let sep_change = if self._left_title == self._first_title
\ s:get_separator_change(group, "", outer_left_group, sep_size, alt_sep_size) + let sep_change = s:get_separator_change(group, "", outer_left_group, sep_size, alt_sep_size)
\ s:get_separator_change(group, "", outer_right_group, sep_size, alt_sep_size) else
let sep_change = s:get_separator_change(group, "", self.overflow_group, sep_size, alt_sep_size)
endif
if self._left_title == self._last_title
let sep_change += s:get_separator_change(group, "", outer_right_group, sep_size, alt_sep_size)
else
let sep_change += s:get_separator_change(group, "", self.overflow_group, sep_size, alt_sep_size)
endif
let left_group = group let left_group = group
let right_group = group let right_group = group
let self._left_title -= let self._left_title -=
@ -129,8 +143,11 @@ function! s:prototype.build() dict
if !center_active && self._right_title <= self._last_title if !center_active && self._right_title <= self._last_title
" Add the title to the right " Add the title to the right
let group = self.get_group(self._right_title) let group = self.get_group(self._right_title)
let sep_change = if self._right_title == self._last_title
\ s:get_separator_change(group, right_group, outer_right_group, sep_size, alt_sep_size) let sep_change = s:get_separator_change_with_end(group, right_group, outer_right_group, self.overflow_group, sep_size, alt_sep_size) - overflow_marker_size
else
let sep_change = s:get_separator_change(group, right_group, self.overflow_group, sep_size, alt_sep_size)
endif
let right_group = group let right_group = group
let self._right_title += let self._right_title +=
\ self.try_insert_title(self._right_title, group, self._right_position, sep_change, 1) \ self.try_insert_title(self._right_title, group, self._right_position, sep_change, 1)
@ -141,8 +158,11 @@ function! s:prototype.build() dict
if self._left_title >= self._first_title if self._left_title >= self._first_title
" Insert next title to the left " Insert next title to the left
let group = self.get_group(self._left_title) let group = self.get_group(self._left_title)
let sep_change = if self._left_title == self._first_title
\ s:get_separator_change(group, left_group, outer_left_group, sep_size, alt_sep_size) let sep_change = s:get_separator_change_with_end(group, left_group, outer_left_group, self.overflow_group, sep_size, alt_sep_size) - overflow_marker_size
else
let sep_change = s:get_separator_change(group, left_group, self.overflow_group, sep_size, alt_sep_size)
endif
let left_group = group let left_group = group
let done = self.try_insert_title(self._left_title, group, self._left_position, sep_change, 0) let done = self.try_insert_title(self._left_title, group, self._left_position, sep_change, 0)
let self._left_title -= done let self._left_title -= done
@ -152,8 +172,11 @@ function! s:prototype.build() dict
if self._right_title <= self._last_title && (center_active || !done) if self._right_title <= self._last_title && (center_active || !done)
" Insert next title to the right " Insert next title to the right
let group = self.get_group(self._right_title) let group = self.get_group(self._right_title)
let sep_change = if self._right_title == self._last_title
\ s:get_separator_change(group, right_group, outer_right_group, sep_size, alt_sep_size) let sep_change = s:get_separator_change_with_end(group, right_group, outer_right_group, self.overflow_group, sep_size, alt_sep_size) - overflow_marker_size
else
let sep_change = s:get_separator_change(group, right_group, self.overflow_group, sep_size, alt_sep_size)
endif
let right_group = group let right_group = group
let done = self.try_insert_title(self._right_title, group, self._right_position, sep_change, 0) let done = self.try_insert_title(self._right_title, group, self._right_position, sep_change, 0)
let self._right_title += done let self._right_title += done
@ -167,12 +190,12 @@ function! s:prototype.build() dict
if get(g:, 'airline#extensions#tabline#current_first', 0) if get(g:, 'airline#extensions#tabline#current_first', 0)
let self._left_position -= 1 let self._left_position -= 1
endif endif
call self.insert_raw('%#'.self.overflow_group.'#'.overflow_marker, self._left_position) call self.insert_section(self.overflow_group, overflow_marker, self._left_position)
let self._right_position += 1 let self._right_position += 1
endif endif
if self._right_title <= self._last_title if self._right_title <= self._last_title
call self.insert_raw('%#'.self.overflow_group.'#'.overflow_marker, self._right_position) call self.insert_section(self.overflow_group, overflow_marker, self._right_position)
endif endif
endif endif