aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorYasuhiro Matsumoto2022-03-17 01:45:37 +0900
committerYasuhiro Matsumoto2022-03-17 01:45:37 +0900
commit9a55567d237f68b497d8fad0dbffa02e63c1146a (patch)
treeccad628c2d1be6c27d7959808dd141d1e42834ad
parentd5b092036bc651912474f64277913be8502f8f09 (diff)
downloadctrlp.vim-9a55567d237f68b497d8fad0dbffa02e63c1146a.tar.gz

Optimize s:pathshorten()

-rw-r--r--autoload/ctrlp.vim15
1 files changed, 10 insertions, 5 deletions
diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim
index 1b6b8c5..e71f191 100644
--- a/autoload/ctrlp.vim
+++ b/autoload/ctrlp.vim
@@ -1767,11 +1767,16 @@ fu! s:formatline2(ct, key, str)
retu s:lineprefix.( cond ? s:pathshorten(str) : str )
endf
-
-fu! s:pathshorten(str)
- retu matchstr(a:str, '^.\{9}').'...'
- \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
-endf
+if exists('*strchars') && exists('*strcharpart')
+ fu! s:pathshorten(str)
+ retu strcharpart(a:str, 0, 9).'...'.strcharpart(a:str, strchars(a:str) - s:winw + 16)
+ endf
+el
+ fu! s:pathshorten(str)
+ retu matchstr(a:str, '^.\{9}').'...'
+ \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
+ endf
+en
fu! s:offset(lines, height)
let s:offset = s:mw_order == 'btt' ? ( a:height - s:res_count ) : 0