Skip to content

Commit

Permalink
Merge pull request #830 from bravestarr/fix-multibyte-path
Browse files Browse the repository at this point in the history
Display a path with multi-byte characters correctly when it is truncated
  • Loading branch information
PhilRunninger authored Apr 24, 2018
2 parents ec3c3b0 + 6aff1b6 commit d3a7cd2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/nerdtree/bookmark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,17 @@ endfunction
" FUNCTION: Bookmark.str() {{{1
" Get the string that should be rendered in the view for this bookmark
function! s:Bookmark.str()
let pathStrMaxLen = winwidth(g:NERDTree.GetWinNum()) - 4 - len(self.name)
let pathStrMaxLen = winwidth(g:NERDTree.GetWinNum()) - 4 - strdisplaywidth(self.name)
if &nu
let pathStrMaxLen = pathStrMaxLen - &numberwidth
endif

let pathStr = self.path.str({'format': 'UI'})
if len(pathStr) > pathStrMaxLen
let pathStr = '<' . strpart(pathStr, len(pathStr) - pathStrMaxLen)
if strdisplaywidth(pathStr) > pathStrMaxLen
while strdisplaywidth(pathStr) > pathStrMaxLen && strchars(pathStr) > 0
let pathStr = strcharpart(pathStr, 1)
endwhile
let pathStr = '<' . pathStr
endif
return '>' . self.name . ' ' . pathStr
endfunction
Expand Down
6 changes: 4 additions & 2 deletions lib/nerdtree/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,10 @@ function! s:Path.str(...)

if has_key(options, 'truncateTo')
let limit = options['truncateTo']
if len(toReturn) > limit-1
let toReturn = toReturn[(len(toReturn)-limit+1):]
if strdisplaywidth(toReturn) > limit-1
while strdisplaywidth(toReturn) > limit-1 && strchars(toReturn) > 0
let toReturn = strcharpart(toReturn, 1)
endwhile
if len(split(toReturn, '/')) > 1
let toReturn = '</' . join(split(toReturn, '/')[1:], '/') . '/'
else
Expand Down

0 comments on commit d3a7cd2

Please sign in to comment.