mirror of
https://github.com/preservim/nerdtree.git
synced 2025-02-12 20:24:00 +08:00
move the path string truncation into Path#str()
This commit is contained in:
parent
a713a86f06
commit
f34986d30f
|
@ -2208,16 +2208,18 @@ endfunction
|
||||||
"The dict may have the following keys:
|
"The dict may have the following keys:
|
||||||
" 'format'
|
" 'format'
|
||||||
" 'escape'
|
" 'escape'
|
||||||
|
" 'truncateTo'
|
||||||
"
|
"
|
||||||
"The 'format' key may have a value of:
|
"The 'format' key may have a value of:
|
||||||
" 'Cd' - a string to be used with the :cd command
|
" 'Cd' - a string to be used with the :cd command
|
||||||
" 'Edit' - a string to be used with :e :sp :new :tabedit etc
|
" 'Edit' - a string to be used with :e :sp :new :tabedit etc
|
||||||
" 'UI' - a string used in the NERD tree UI
|
" 'UI' - a string used in the NERD tree UI
|
||||||
"
|
"
|
||||||
"If not specified, a generic unix style path string will be returned
|
|
||||||
"
|
|
||||||
"The 'escape' key, if specified will cause the output to be escaped with
|
"The 'escape' key, if specified will cause the output to be escaped with
|
||||||
"shellescape()
|
"shellescape()
|
||||||
|
"
|
||||||
|
"The 'truncateTo' key causes the resulting string to be truncated to the value
|
||||||
|
"'truncateTo' maps to. A '<' char will be prepended.
|
||||||
function! s:Path.str(...)
|
function! s:Path.str(...)
|
||||||
let options = a:0 ? a:1 : {}
|
let options = a:0 ? a:1 : {}
|
||||||
let toReturn = ""
|
let toReturn = ""
|
||||||
|
@ -2237,6 +2239,13 @@ function! s:Path.str(...)
|
||||||
let toReturn = shellescape(toReturn)
|
let toReturn = shellescape(toReturn)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if has_key(options, 'truncateTo')
|
||||||
|
let limit = options['truncateTo']
|
||||||
|
if len(toReturn) > limit
|
||||||
|
let toReturn = "<" . strpart(toReturn, len(toReturn) - limit + 1)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
return toReturn
|
return toReturn
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -3133,12 +3142,7 @@ function! s:renderView()
|
||||||
call cursor(line(".")+1, col("."))
|
call cursor(line(".")+1, col("."))
|
||||||
|
|
||||||
"draw the header line
|
"draw the header line
|
||||||
let header = b:NERDTreeRoot.path.str({'format': 'UI'})
|
let header = b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
|
||||||
let wid = winwidth(0)
|
|
||||||
if len(header) > wid
|
|
||||||
let header = "<" . strpart(header, len(header) - wid + 1)
|
|
||||||
endif
|
|
||||||
|
|
||||||
call setline(line(".")+1, header)
|
call setline(line(".")+1, header)
|
||||||
call cursor(line(".")+1, col("."))
|
call cursor(line(".")+1, col("."))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user