aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authormattn2022-03-17 02:25:29 +0900
committerGitHub2022-03-17 02:25:29 +0900
commitacbff25680820cd5d52a608a774c816f15e20859 (patch)
treee36b7cd4c0bceb0161cbbc0d366c19addd0faf37
parent3b488a5cc557d75bcf37440d3e07e1bbac0ad4c6 (diff)
parentf75c3291f44f4d0c11257f089475fc3682afb6cb (diff)
downloadctrlp.vim-acbff25680820cd5d52a608a774c816f15e20859.tar.gz

Merge pull request #595 from ctrlpvim/optimize4

Optimize s:pathshorten()

-rw-r--r--autoload/ctrlp.vim18
1 files changed, 12 insertions, 6 deletions
diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim
index 06eb9ff..cdf9509 100644
--- a/autoload/ctrlp.vim
+++ b/autoload/ctrlp.vim
@@ -1764,16 +1764,22 @@ fu! s:formatline2(ct, key, str)
let str .= printf(' %s', parts[3])
en
en
+ retu s:lineprefix.str
en
- let cond = a:ct != 'buf' &&s:ispath && ( s:winw - 4 ) < s:strwidth(str)
+ let cond = s:ispath && ( s:winw - 4 ) < strchars(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