mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-07-27 07:54:44 +02:00
fix vim-airline/fern does not update the branch name as you navigate through fern, and theme fern inactive windows too (#2698)
Co-authored-by: Neil Lambert <nlambert@pm.me>
This commit is contained in:
parent
3ddcab16c2
commit
6c704f4b78
@ -7,30 +7,47 @@ if !get(g:, 'loaded_fern', 0)
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! airline#extensions#fern#apply(...) abort
|
function! airline#extensions#fern#apply_active(...) abort
|
||||||
if (&ft =~# 'fern')
|
" check if current buffer is both fern and active
|
||||||
let spc = g:airline_symbols.space
|
if (&ft =~# 'fern') && a:2.active ==# '1'
|
||||||
let fri = fern#fri#parse(expand('%f'))
|
call airline#extensions#fern#configure_sections(a:1, a:2)
|
||||||
|
|
||||||
call a:1.add_section('airline_a', spc.'fern'.spc)
|
|
||||||
if exists('*airline#extensions#branch#get_head')
|
|
||||||
call a:1.add_section('airline_b', spc.'%{airline#extensions#branch#get_head()}'.spc)
|
|
||||||
else
|
|
||||||
call a:1.add_section('airline_b', '')
|
|
||||||
endif
|
|
||||||
if !(fri.authority =~# '^drawer')
|
|
||||||
let abspath = substitute(fri.path, 'file://', '', '')
|
|
||||||
call a:1.add_section('airline_c', spc.fnamemodify(abspath, ':~'))
|
|
||||||
call a:1.split()
|
|
||||||
if len(get(g:, 'fern#comparators', {}))
|
|
||||||
call a:1.add_section('airline_y', spc.'%{fern#comparator}'.spc)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! airline#extensions#fern#apply_inactive(...) abort
|
||||||
|
" check if referenced buffer is both fern and inactive
|
||||||
|
if getbufvar(a:2.bufnr, '&filetype') ==# 'fern' && a:2.active ==# '0'
|
||||||
|
call airline#extensions#fern#configure_sections(a:1, a:2)
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! airline#extensions#fern#configure_sections(win, context) abort
|
||||||
|
let spc = g:airline_symbols.space
|
||||||
|
let fri = fern#fri#parse(bufname(a:context.bufnr))
|
||||||
|
let abspath = substitute(fri.path, 'file://', '', '')
|
||||||
|
call a:win.add_section('airline_a', spc.'fern'.spc)
|
||||||
|
if exists('*airline#extensions#branch#get_head')
|
||||||
|
" because fern navigation changes an internal _fri_ and not the working directory
|
||||||
|
" we need to give it some help so the branch name gets updated
|
||||||
|
execute 'lcd' abspath
|
||||||
|
call a:win.add_section('airline_b', spc.'%{airline#extensions#branch#get_head()}'.spc)
|
||||||
|
else
|
||||||
|
call a:win.add_section('airline_b', '')
|
||||||
|
endif
|
||||||
|
if !(fri.authority =~# '^drawer')
|
||||||
|
call a:win.add_section('airline_c', spc.fnamemodify(abspath, ':~'))
|
||||||
|
call a:win.split()
|
||||||
|
if len(get(g:, 'fern#comparators', {}))
|
||||||
|
call a:win.add_section('airline_y', spc.'%{fern#comparator}'.spc)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#fern#init(ext) abort
|
function! airline#extensions#fern#init(ext) abort
|
||||||
let g:fern_force_overwrite_statusline = 0
|
let g:fern_force_overwrite_statusline = 0
|
||||||
call a:ext.add_statusline_func('airline#extensions#fern#apply')
|
call a:ext.add_statusline_func('airline#extensions#fern#apply_active')
|
||||||
|
call a:ext.add_inactive_statusline_func('airline#extensions#fern#apply_inactive')
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user