mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-08 11:23:48 -05:00
Rewrite the "Path._strForEdit()" method
This method used the brittle "Path._escChars()" method to do its
work. This created problems when 'shellslash' was in use on Windows
because excessive escape characters (i.e., backslashes!) are
interpreted by Vim as additional path separators.
The above problem made it impossible to edit files with weird names
using the NERDTree on Windows with 'shellslash' set. For example,
'+' should be escaped with ":edit", but '(' should not. So, when
escaping '(', Vim on Windows correctly sees the start of a new
directory in the path.
This was reported in five issues which may be read for further
details and commentary.
Fixes #398, fixes #474, fixes #653, fixes #674, and fixes #733.
This commit is contained in:
@@ -726,22 +726,23 @@ endfunction
|
||||
" Return a string representation of this Path that is suitable for use as an
|
||||
" argument to Vim's internal ":edit" command.
|
||||
function! s:Path._strForEdit()
|
||||
let p = escape(self.str(), self._escChars())
|
||||
|
||||
"make it relative
|
||||
let p = fnamemodify(p, ':.')
|
||||
" Make the path relative to the current working directory, if possible.
|
||||
let l:result = fnamemodify(self.str(), ':.')
|
||||
|
||||
"handle the edge case where the file begins with a + (vim interprets
|
||||
"the +foo in `:e +foo` as an option to :edit)
|
||||
if p[0] == "+"
|
||||
let p = '\' . p
|
||||
" On Windows, the drive letter may be removed by "fnamemodify()". Add it
|
||||
" back, if necessary.
|
||||
if nerdtree#runningWindows() && l:result[0] == s:Path.Slash()
|
||||
let l:result = self.drive . l:result
|
||||
endif
|
||||
|
||||
if p ==# ''
|
||||
let p = '.'
|
||||
let l:result = fnameescape(l:result)
|
||||
|
||||
if empty(l:result)
|
||||
let l:result = '.'
|
||||
endif
|
||||
|
||||
return p
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
" FUNCTION: Path._strForGlob() {{{1
|
||||
|
||||
Reference in New Issue
Block a user