Merge pull request #1738 from shirohana/fix/ctrlspace-tabline-switching

airline#extensions#ctrlspace: Fix tabline didn't update when switch to tab which focused on non-listed buffer
This commit is contained in:
Christian Brabandt 2018-06-04 22:56:22 +02:00 committed by GitHub
commit add75907d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ scriptencoding utf-8
let s:current_bufnr = -1 let s:current_bufnr = -1
let s:current_tabnr = -1 let s:current_tabnr = -1
let s:current_tabline = '' let s:current_tabline = ''
let s:highlight_groups = ['hid', 0, '', 'sel', 'mod_unsel', 0, 'mod_unsel', 'mod']
function! airline#extensions#tabline#ctrlspace#off() function! airline#extensions#tabline#ctrlspace#off()
augroup airline_tabline_ctrlspace augroup airline_tabline_ctrlspace
@ -25,39 +26,23 @@ function! airline#extensions#tabline#ctrlspace#invalidate()
let s:current_tabnr = -1 let s:current_tabnr = -1
endfunction endfunction
function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pos) function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, pull_right)
if a:pos == 0 let pos_extension = (a:pull_right ? '_right' : '')
let pos_extension = '' let buffer_list = ctrlspace#api#BufferList(a:cur_tab)
else
let pos_extension = '_right'
endif
let s:buffer_list = ctrlspace#api#BufferList(a:cur_tab)
" add by tenfy(tenfyzhong@qq.com) " add by tenfy(tenfyzhong@qq.com)
" if the current buffer no in the buffer list " if the current buffer no in the buffer list
" return false and no redraw tabline. " return false and no redraw tabline.
" Fixes #1515. if there a BufEnter autocmd execute redraw. The tabline may no update. " Fixes #1515. if there a BufEnter autocmd execute redraw. The tabline may no update.
let bufnr_list = map(copy(s:buffer_list), 'v:val["index"]') let bufnr_list = map(copy(buffer_list), 'v:val["index"]')
if index(bufnr_list, a:cur_buf) == -1 if index(bufnr_list, a:cur_buf) == -1 && a:cur_tab == s:current_tabnr
return 0 return 0
endif endif
for buffer in s:buffer_list for buffer in buffer_list
if a:cur_buf == buffer.index let group = 'airline_tab'
if buffer.modified \ .s:highlight_groups[(4 * buffer.modified) + (2 * buffer.visible) + (a:cur_buf == buffer.index)]
let group = 'airline_tabmod'.pos_extension \ .pos_extension
else
let group = 'airline_tabsel'.pos_extension
endif
else
if buffer.modified
let group = 'airline_tabmod_unsel'.pos_extension
elseif buffer.visible
let group = 'airline_tab'.pos_extension
else
let group = 'airline_tabhid'.pos_extension
endif
endif
let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)' let buf_name = '%(%{airline#extensions#tabline#get_buffer_name('.buffer.index.')}%)'
@ -73,27 +58,14 @@ function! airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_t
return 1 return 1
endfunction endfunction
function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pos) function! airline#extensions#tabline#ctrlspace#add_tab_section(builder, pull_right)
if a:pos == 0 let pos_extension = (a:pull_right ? '_right' : '')
let pos_extension = '' let tab_list = ctrlspace#api#TabList()
else
let pos_extension = '_right'
endif
for tab in s:tab_list for tab in tab_list
if tab.current let group = 'airline_tab'
if tab.modified \ .s:highlight_groups[(4 * tab.modified) + (3 * tab.current)]
let group = 'airline_tabmod'.pos_extension \ .pos_extension
else
let group = 'airline_tabsel'.pos_extension
endif
else
if tab.modified
let group = 'airline_tabmod_unsel'.pos_extension
else
let group = 'airline_tabhid'.pos_extension
endif
endif
call a:builder.add_section_spaced(group, '%'.tab.index.'T'.tab.title.ctrlspace#api#TabBuffersNumber(tab.index).'%T') call a:builder.add_section_spaced(group, '%'.tab.index.'T'.tab.title.ctrlspace#api#TabBuffersNumber(tab.index).'%T')
endfor endfor
@ -107,15 +79,9 @@ function! airline#extensions#tabline#ctrlspace#get()
try try
call airline#extensions#tabline#tabs#map_keys() call airline#extensions#tabline#tabs#map_keys()
catch
" no-op
endtry endtry
let s:tab_list = ctrlspace#api#TabList()
for tab in s:tab_list let cur_tab = tabpagenr()
if tab.current
let cur_tab = tab.index
endif
endfor
if cur_buf == s:current_bufnr && cur_tab == s:current_tabnr if cur_buf == s:current_bufnr && cur_tab == s:current_tabnr
return s:current_tabline return s:current_tabline
@ -123,52 +89,57 @@ function! airline#extensions#tabline#ctrlspace#get()
let builder = airline#extensions#tabline#new_builder() let builder = airline#extensions#tabline#new_builder()
let show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
let show_tabs = get(g:, 'airline#extensions#tabline#show_tabs', 1)
let AppendBuffers = function('airline#extensions#tabline#ctrlspace#add_buffer_section', [builder, cur_tab, cur_buf])
let AppendTabs = function('airline#extensions#tabline#ctrlspace#add_tab_section', [builder])
let AppendLabel = function(builder.add_section_spaced, ['airline_tabtype'], builder)
" <= 1: |{Tabs} <tab|
" == 2: |{Buffers} <buffers|
" == 3: |buffers> {Buffers} {Tabs} <tabs|
let showing_mode = (2 * show_buffers) + (show_tabs)
let ignore_update = 0
" Add left tabline content " Add left tabline content
if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0 if showing_mode <= 1 " Tabs only mode
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) call AppendTabs(0)
elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0 elseif showing_mode == 2 " Buffers only mode
" add by tenfy(tenfyzhong@qq.com) let ignore_update = !AppendBuffers(0)
" if current buffer no in the buffer list, does't update tabline
if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) == 0
return s:current_tabline
endif
else else
if switch_buffers_and_tabs == 0 if !switch_buffers_and_tabs
call builder.add_section_spaced('airline_tabtype', buffer_label) call AppendLabel(buffer_label)
" add by tenfy(tenfyzhong@qq.com) let ignore_update = !AppendBuffers(0)
" if current buffer no in the buffer list, does't update tabline
if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 0) == 0
return s:current_tabline
endif
else else
call builder.add_section_spaced('airline_tabtype', tab_label) call AppendLabel(tab_label)
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 0) call AppendTabs(0)
endif endif
endif endif
if ignore_update | return s:current_tabline | endif
call builder.add_section('airline_tabfill', '') call builder.add_section('airline_tabfill', '')
call builder.split() call builder.split()
call builder.add_section('airline_tabfill', '') call builder.add_section('airline_tabfill', '')
" Add right tabline content " Add right tabline content
if get(g:, 'airline#extensions#tabline#show_buffers', 1) == 0 if showing_mode <= 1 " Tabs only mode
call builder.add_section_spaced('airline_tabtype', tab_label) call AppendLabel(tab_label)
elseif get(g:, 'airline#extensions#tabline#show_tabs', 1) == 0 elseif showing_mode == 2 " Buffers only mode
call builder.add_section_spaced('airline_tabtype', buffer_label) call AppendLabel(buffer_label)
else else
if switch_buffers_and_tabs == 0 if !switch_buffers_and_tabs
call airline#extensions#tabline#ctrlspace#add_tab_section(builder, 1) call AppendTabs(1)
call builder.add_section_spaced('airline_tabtype', tab_label) call AppendLabel(tab_label)
else else
" add by tenfy(tenfyzhong@qq.com) let ignore_update = AppendBuffers(1)
" if current buffer no in the buffer list, does't update tabline call AppendLabel(buffer_label)
if airline#extensions#tabline#ctrlspace#add_buffer_section(builder, cur_tab, cur_buf, 1) == 0
return s:current_tabline
endif
call builder.add_section_spaced('airline_tabtype', buffer_label)
endif endif
endif endif
if ignore_update | return s:current_tabline | endif
let s:current_bufnr = cur_buf let s:current_bufnr = cur_buf
let s:current_tabnr = cur_tab let s:current_tabnr = cur_tab
let s:current_tabline = builder.build() let s:current_tabline = builder.build()