mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-07-21 21:14:47 +02:00
Cache hunk values, shorten for small windows
Cache the hunk values. In case of short windows, shorten the hunk string a little bit and make the branch extension take the hunk value into account when deciding how much to shorten it.
This commit is contained in:
parent
a710cb99dd
commit
8fda614d0d
@ -166,7 +166,8 @@ function! airline#extensions#branch#head()
|
|||||||
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
|
||||||
let b:airline_head = ''
|
let b:airline_head = ''
|
||||||
endif
|
endif
|
||||||
let b:airline_head = airline#util#shorten(b:airline_head, 120, 9)
|
let minwidth = empty(get(b:, 'airline_hunks', '')) ? 14 : 7
|
||||||
|
let b:airline_head = airline#util#shorten(b:airline_head, 120, minwidth)
|
||||||
return b:airline_head
|
return b:airline_head
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -65,19 +65,27 @@ function! airline#extensions#hunks#get_hunks()
|
|||||||
if !get(w:, 'airline_active', 0)
|
if !get(w:, 'airline_active', 0)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
" Cache vavlues, so that it isn't called too often
|
||||||
|
if exists("b:airline_hunks") &&
|
||||||
|
\ get(b:, 'airline_changenr', 0) == changenr() &&
|
||||||
|
\ winwidth(0) == get(s:, 'airline_winwidth', 0)
|
||||||
|
return b:airline_hunks
|
||||||
|
endif
|
||||||
let hunks = s:get_hunks()
|
let hunks = s:get_hunks()
|
||||||
let string = ''
|
let string = ''
|
||||||
if !empty(hunks)
|
if !empty(hunks)
|
||||||
for i in [0, 1, 2]
|
for i in [0, 1, 2]
|
||||||
if s:non_zero_only == 0 || hunks[i] > 0
|
if (s:non_zero_only == 0 && winwidth(0) > 100) || hunks[i] > 0
|
||||||
let string .= printf('%s%s ', s:hunk_symbols[i], hunks[i])
|
let string .= printf('%s%s ', s:hunk_symbols[i], hunks[i])
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
|
let b:airline_hunks = string
|
||||||
|
let b:airline_changenr = changenr()
|
||||||
|
let s:airline_winwidth = winwidth(0)
|
||||||
return string
|
return string
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#hunks#init(ext)
|
function! airline#extensions#hunks#init(ext)
|
||||||
call airline#parts#define_function('hunks', 'airline#extensions#hunks#get_hunks')
|
call airline#parts#define_function('hunks', 'airline#extensions#hunks#get_hunks')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user