Use variables in the tabs tabline builder to track position
This commit is contained in:
parent
349d01ba39
commit
ada8cd7641
@ -15,10 +15,10 @@ function! s:prototype.build() dict
|
|||||||
let tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
let tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
||||||
let num_tabs = tabpagenr('$')
|
let num_tabs = tabpagenr('$')
|
||||||
let curtab = self._curtab
|
let curtab = self._curtab
|
||||||
let left_tab = curtab - 1
|
let self._left_tab = curtab - 1
|
||||||
let right_tab = curtab + 1
|
let self._right_tab = curtab + 1
|
||||||
let left_position = self._tabs_position
|
let self._left_position = self._tabs_position
|
||||||
let right_position = self._tabs_position + 1
|
let self._right_position = self._tabs_position + 1
|
||||||
let remaining_space = &columns - s:strchars(s:evaluate_tabline(self._build()))
|
let remaining_space = &columns - s:strchars(s:evaluate_tabline(self._build()))
|
||||||
|
|
||||||
let left_sep_size = s:strchars(s:evaluate_tabline(self._context.left_sep))
|
let left_sep_size = s:strchars(s:evaluate_tabline(self._context.left_sep))
|
||||||
@ -35,54 +35,54 @@ function! s:prototype.build() dict
|
|||||||
" There are always two left_seps (either side of the selected tab) and all
|
" There are always two left_seps (either side of the selected tab) and all
|
||||||
" other seperators are left_alt_seps.
|
" other seperators are left_alt_seps.
|
||||||
let remaining_space -= 2 * left_sep_size - left_alt_sep_size
|
let remaining_space -= 2 * left_sep_size - left_alt_sep_size
|
||||||
call self.insert_section(self.get_group(curtab), tab_title, left_position)
|
call self.insert_section(self.get_group(curtab), tab_title, self._left_position)
|
||||||
|
|
||||||
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
||||||
" always have current tabpage first
|
" always have current tabpage first
|
||||||
let left_position += 1
|
let self._left_position += 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Add the tab to the right
|
" Add the tab to the right
|
||||||
if right_tab <= num_tabs
|
if self._right_tab <= num_tabs
|
||||||
let tab_title = self.get_title(tab_nr_type, right_tab)
|
let tab_title = self.get_title(tab_nr_type, self._right_tab)
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
||||||
call self.insert_section(self.get_group(right_tab), tab_title, right_position)
|
call self.insert_section(self.get_group(self._right_tab), tab_title, self._right_position)
|
||||||
let right_position += 1
|
let self._right_position += 1
|
||||||
let right_tab += 1
|
let self._right_tab += 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
while remaining_space > 0
|
while remaining_space > 0
|
||||||
if left_tab > 0
|
if self._left_tab > 0
|
||||||
let tab_title = self.get_title(tab_nr_type, left_tab)
|
let tab_title = self.get_title(tab_nr_type, self._left_tab)
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
||||||
if remaining_space >= 0
|
if remaining_space >= 0
|
||||||
call self.insert_section(self.get_group(left_tab), tab_title, left_position)
|
call self.insert_section(self.get_group(self._left_tab), tab_title, self._left_position)
|
||||||
let right_position += 1
|
let self._right_position += 1
|
||||||
let left_tab -= 1
|
let self._left_tab -= 1
|
||||||
endif
|
endif
|
||||||
elseif right_tab <= num_tabs
|
elseif self._right_tab <= num_tabs
|
||||||
let tab_title = self.get_title(tab_nr_type, right_tab)
|
let tab_title = self.get_title(tab_nr_type, self._right_tab)
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
||||||
if remaining_space >= 0
|
if remaining_space >= 0
|
||||||
call self.insert_section(self.get_group(right_tab), tab_title, right_position)
|
call self.insert_section(self.get_group(self._right_tab), tab_title, self._right_position)
|
||||||
let right_position += 1
|
let self._right_position += 1
|
||||||
let right_tab += 1
|
let self._right_tab += 1
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
if left_tab > 0
|
if self._left_tab > 0
|
||||||
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
||||||
let left_position -= 1
|
let self._left_position -= 1
|
||||||
endif
|
endif
|
||||||
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, left_position)
|
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, self._left_position)
|
||||||
let right_position += 1
|
let self._right_position += 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if right_tab <= num_tabs
|
if self._right_tab <= num_tabs
|
||||||
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, right_position)
|
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, self._right_position)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user