Skip to content

Commit acbff25

Browse files
authored
Merge pull request #595 from ctrlpvim/optimize4
Optimize s:pathshorten()
2 parents 3b488a5 + f75c329 commit acbff25

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

autoload/ctrlp.vim

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,16 +1764,22 @@ fu! s:formatline2(ct, key, str)
17641764
let str .= printf(' %s', parts[3])
17651765
en
17661766
en
1767+
retu s:lineprefix.str
17671768
en
1768-
let cond = a:ct != 'buf' &&s:ispath && ( s:winw - 4 ) < s:strwidth(str)
1769+
let cond = s:ispath && ( s:winw - 4 ) < strchars(str)
17691770
retu s:lineprefix.( cond ? s:pathshorten(str) : str )
17701771
endf
17711772

1772-
1773-
fu! s:pathshorten(str)
1774-
retu matchstr(a:str, '^.\{9}').'...'
1775-
\ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
1776-
endf
1773+
if exists('*strchars') && exists('*strcharpart')
1774+
fu! s:pathshorten(str)
1775+
retu strcharpart(a:str, 0, 9).'...'.strcharpart(a:str, strchars(a:str) - s:winw + 16)
1776+
endf
1777+
el
1778+
fu! s:pathshorten(str)
1779+
retu matchstr(a:str, '^.\{9}').'...'
1780+
\ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
1781+
endf
1782+
en
17771783

17781784
fu! s:offset(lines, height)
17791785
let s:offset = s:mw_order == 'btt' ? ( a:height - s:res_count ) : 0

0 commit comments

Comments
 (0)