Skip to content

Commit 9a55567

Browse files
committed
Optimize s:pathshorten()
1 parent d5b0920 commit 9a55567

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

autoload/ctrlp.vim

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,11 +1767,16 @@ fu! s:formatline2(ct, key, str)
17671767
retu s:lineprefix.( cond ? s:pathshorten(str) : str )
17681768
endf
17691769

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

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

0 commit comments

Comments
 (0)