Compare commits

...

9 Commits

Author SHA1 Message Date
Phil Runninger
f63132cade Use backward-compatible nerdtree#and() in one place that was missed. (#1134)
* Use backward-compatible nerdtree#and() in one place that was missed.

* Update version number in change log.
2020-05-25 11:33:20 -04:00
Phil Runninger
484dc84b47 Update title of pull request. Add PR authors where missing. 2020-05-22 09:02:39 -04:00
Jordi Altayó
2e9d43b6f8 cmd.exe /c start "" <filename> for windows default viewer support (#1130)
* support for default viewer in Windows

* updated changelog

* Update nerdtree_plugin/fs_menu.vim

Co-authored-by: Phil Runninger <PhilRunninger@users.noreply.github.com>

* Update nerdtree_plugin/fs_menu.vim

Co-authored-by: Phil Runninger <PhilRunninger@users.noreply.github.com>

Co-authored-by: Phil Runninger <PhilRunninger@users.noreply.github.com>
2020-05-22 08:57:19 -04:00
Eugenij
10eaa3a2f4 Fixed a bug that caused the file-tree construction to slow down significantly. (#1126)
Co-authored-by: evgenij.vidershpan <evgenij.vidershpan@yandex.ru>
2020-05-21 02:23:35 -04:00
Eugenij
e2670f0d19 * fix duplicated slash in s:Path.isUnder() (on windows OS) (#1122)
* * fix duplicated slash in s:Path.isUnder() (on windows OS, for root directory on drive Path.str() return path with [back]slash)

* * Rewrite NERDTreePath.isUnder() and NERDTreePath.isAncestor() for direct comparison of paths without transformations

* Remove trailing slash, so we don't end up with two on root folder.

The str() function returns "C:\" on the root folder and "C:\temp" on
non-root folders, one with and one without a trailing backslash. This
inconsistency needs to be handled so the stridx() function will work
correctly.

* Make sure the change also works in a non-windows file system.

This commit handles an edge case that can be triggered with these
commands:
    :cd /home/me
    :e /foobar.txt  (an existing file)
    :NERDTreeFind
What happened was the root directory name '/' was being Resolved(), and
the trailing (and only) slash was being removed. The NERDTree was then
created in the current working directory, instead of the root directory.
:NERDTreeFind then wasn't able to find foobar.txt, and printed an error.

* Remove degugging statements.

* * ambiguity issue fix

Co-authored-by: Phil Runninger <philrunninger@gmail.com>
2020-05-14 14:24:36 -04:00
lifecrisis
4cc6097ecb Do not consider the tree root to be "cascadable" (#1120)
* Do not consider the tree root to be "cascadable"

* Update "CHANGELOG.md"
2020-05-06 23:24:01 -04:00
Phil Runninger
30ad6da984 Force NERDTreeFocus to allow events to be fired when switching windows. (#1118) 2020-05-04 08:14:22 -04:00
Phil Runninger
3005a0e9c0 Update version number in change log. 2020-05-04 08:11:49 -04:00
Phil Runninger
a7d585f7af Force NERDTreeFocus to allow events to be fired when switching windows. 2020-05-04 07:59:25 -04:00
9 changed files with 64 additions and 22 deletions

View File

@@ -5,8 +5,14 @@
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
--> -->
#### 6.7 #### 6.7
- **.8**: Fix example code for the NERDTreeAddKeyMap function. (PhilRunninger) [#1116](https://github.com/preservim/nerdtree/pull/1116) - **.14**: Use backward-compatible `nerdtree#and()` in one place that was missed. (PhilRunninger) [#1134](https://github.com/preservim/nerdtree/pull/1134)
- **.7**: Put '%' argument in bufname() for backwards compatibility. (PhilRunninger) [#1105](https://github.com/preservim/nerdtree/pull/1105) - **.13**: `cmd.exe /c start "" <filename>` for windows default viewer support. (J. Altayó) [#1130](https://github.com/preservim/nerdtree/pull/1130)
- **.12**: Fixed a bug that caused the file-tree construction to slow down significantly. (Eugenij-W) [#1126](https://github.com/preservim/nerdtree/pull/1126)
- **.11**: Fix exception in NERDTreeFind (on windows OS and If the file is located in the root directory of the disk) (Eugenij-W) [#1122](https://github.com/preservim/nerdtree/pull/1122)
- **.10**: Do not consider the tree root to be "cascadable". (lifecrisis) [#1120](https://github.com/preservim/nerdtree/pull/1120)
- **.9**: Force `:NERDTreeFocus` to allow events to be fired when switching windows. (PhilRunninger) [#1118](https://github.com/preservim/nerdtree/pull/1118)
- **.8**: Fix example code for the `NERDTreeAddKeyMap()` function. (PhilRunninger) [#1116](https://github.com/preservim/nerdtree/pull/1116)
- **.7**: Put `'%'` argument in `bufname()` for backwards compatibility. (PhilRunninger) [#1105](https://github.com/preservim/nerdtree/pull/1105)
- **.6**: If a file's already open in the window, don't edit it again. (PhilRunninger) [#1103](https://github.com/preservim/nerdtree/pull/1103) - **.6**: If a file's already open in the window, don't edit it again. (PhilRunninger) [#1103](https://github.com/preservim/nerdtree/pull/1103)
- **.5**: Prevent unneeded tree creation in `:NERDTreeToggle[VCS] <path>` (PhilRunninger) [#1101](https://github.com/preservim/nerdtree/pull/1101) - **.5**: Prevent unneeded tree creation in `:NERDTreeToggle[VCS] <path>` (PhilRunninger) [#1101](https://github.com/preservim/nerdtree/pull/1101)
- **.4**: Add missing calls to the `shellescape()` function (lifecrisis) [#1099](https://github.com/preservim/nerdtree/pull/1099) - **.4**: Add missing calls to the `shellescape()` function (lifecrisis) [#1099](https://github.com/preservim/nerdtree/pull/1099)

View File

@@ -45,7 +45,7 @@ function! nerdtree#slash() abort
endfunction endfunction
"FUNCTION: nerdtree#and(x,y) {{{2 "FUNCTION: nerdtree#and(x,y) {{{2
" Implements and() function for Vim <= 7.2 " Implements and() function for Vim <= 7.4
function! nerdtree#and(x,y) abort function! nerdtree#and(x,y) abort
if exists('*and') if exists('*and')
return and(a:x, a:y) return and(a:x, a:y)

View File

@@ -249,7 +249,11 @@ function! s:Creator._pathForString(str)
if dir =~# '^\.' if dir =~# '^\.'
let dir = getcwd() . g:NERDTreePath.Slash() . dir let dir = getcwd() . g:NERDTreePath.Slash() . dir
endif endif
let dir = g:NERDTreePath.Resolve(dir)
"hack to prevent removing slash if dir is the root of the file system.
if dir !=# '/'
let dir = g:NERDTreePath.Resolve(dir)
endif
try try
let path = g:NERDTreePath.New(dir) let path = g:NERDTreePath.New(dir)

View File

@@ -96,9 +96,9 @@ endfunction
"FUNCTION: s:NERDTree.CursorToTreeWin(){{{1 "FUNCTION: s:NERDTree.CursorToTreeWin(){{{1
"Places the cursor in the nerd tree window "Places the cursor in the nerd tree window
function! s:NERDTree.CursorToTreeWin() function! s:NERDTree.CursorToTreeWin(...)
call g:NERDTree.MustBeOpen() call g:NERDTree.MustBeOpen()
call nerdtree#exec(g:NERDTree.GetWinNum() . 'wincmd w', 1) call nerdtree#exec(g:NERDTree.GetWinNum() . 'wincmd w', a:0 >0 ? a:1 : 1)
endfunction endfunction
" Function: s:NERDTree.ExistsForBuffer() {{{1 " Function: s:NERDTree.ExistsForBuffer() {{{1

View File

@@ -219,7 +219,7 @@ endfunction
" FUNCTION: Opener._openFile() {{{1 " FUNCTION: Opener._openFile() {{{1
function! s:Opener._openFile() function! s:Opener._openFile()
if !self._stay && !and(g:NERDTreeQuitOnOpen,1) && exists('b:NERDTreeZoomed') && b:NERDTreeZoomed if !self._stay && !nerdtree#and(g:NERDTreeQuitOnOpen,1) && exists('b:NERDTreeZoomed') && b:NERDTreeZoomed
call b:NERDTree.ui.toggleZoom() call b:NERDTree.ui.toggleZoom()
endif endif

View File

@@ -546,26 +546,36 @@ endfunction
" return 1 if this path is somewhere above the given path in the filesystem. " return 1 if this path is somewhere above the given path in the filesystem.
" "
" a:path should be a dir " a:path should be a dir
function! s:Path.isAncestor(path) function! s:Path.isAncestor(child)
if !self.isDirectory return a:child.isUnder(self)
return 0
endif
let this = self.str()
let that = a:path.str()
return stridx(that, this) ==# 0
endfunction endfunction
" FUNCTION: Path.isUnder(path) {{{1 " FUNCTION: Path.isUnder(path) {{{1
" return 1 if this path is somewhere under the given path in the filesystem. " return 1 if this path is somewhere under the given path in the filesystem.
function! s:Path.isUnder(path) function! s:Path.isUnder(parent)
if a:path.isDirectory ==# 0 if a:parent.isDirectory ==# 0
return 0 return 0
endif endif
if nerdtree#runningWindows() && a:parent.drive !=# self.drive
let this = self.str() return 0
let that = a:path.str() endif
return stridx(this, that . s:Path.Slash()) ==# 0 let l:this_count = len(self.pathSegments)
if l:this_count ==# 0
return 0
endif
let l:that_count = len(a:parent.pathSegments)
if l:that_count ==# 0
return 1
endif
if l:that_count >= l:this_count
return 0
endif
for i in range(0, l:that_count-1)
if self.pathSegments[i] !=# a:parent.pathSegments[i]
return 0
endif
endfor
return 1
endfunction endfunction
" FUNCTION: Path.JoinPathStrings(...) {{{1 " FUNCTION: Path.JoinPathStrings(...) {{{1

View File

@@ -377,11 +377,17 @@ endfunction
" 1. If cascaded, we don't know which dir is bookmarked or is a symlink. " 1. If cascaded, we don't know which dir is bookmarked or is a symlink.
" 2. If the parent is a symlink or is bookmarked, you end up with unparsable " 2. If the parent is a symlink or is bookmarked, you end up with unparsable
" text, and NERDTree cannot get the path of any child node. " text, and NERDTree cannot get the path of any child node.
" Also, return false if this directory is the tree root, which should never be
" part of a cascade.
function! s:TreeDirNode.isCascadable() function! s:TreeDirNode.isCascadable()
if g:NERDTreeCascadeSingleChildDir ==# 0 if g:NERDTreeCascadeSingleChildDir ==# 0
return 0 return 0
endif endif
if self.isRoot()
return 0
endif
if self.path.isSymLink if self.path.isSymLink
return 0 return 0
endif endif
@@ -425,6 +431,7 @@ function! s:TreeDirNode._initChildren(silent)
endtry endtry
endfor endfor
let g:NERDTreeOldSortOrder = g:NERDTreeSortOrder
call self.sortChildren() call self.sortChildren()
call nerdtree#echo('') call nerdtree#echo('')

View File

@@ -34,6 +34,10 @@ if executable('xdg-open')
call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFileLinux'}) call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFileLinux'})
endif endif
if nerdtree#runningWindows()
call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFileWindows'})
endif
if g:NERDTreePath.CopyingSupported() if g:NERDTreePath.CopyingSupported()
call NERDTreeAddMenuItem({'text': '(c)opy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'}) call NERDTreeAddMenuItem({'text': '(c)opy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'})
endif endif
@@ -451,4 +455,15 @@ function! NERDTreeExecuteFileLinux()
call system('xdg-open ' . shellescape(l:node.path.str())) call system('xdg-open ' . shellescape(l:node.path.str()))
endfunction endfunction
" FUNCTION: NERDTreeExecuteFileWindows() {{{1
function! NERDTreeExecuteFileWindows()
let l:node = g:NERDTreeFileNode.GetSelected()
if empty(l:node)
return
endif
call system('cmd.exe /c start "" ' . shellescape(l:node.path.str()))
endfunction
" vim: set sw=4 sts=4 et fdm=marker: " vim: set sw=4 sts=4 et fdm=marker:

View File

@@ -217,7 +217,7 @@ endfunction
function! NERDTreeFocus() function! NERDTreeFocus()
if g:NERDTree.IsOpen() if g:NERDTree.IsOpen()
call g:NERDTree.CursorToTreeWin() call g:NERDTree.CursorToTreeWin(0)
else else
call g:NERDTreeCreator.ToggleTabTree('') call g:NERDTreeCreator.ToggleTabTree('')
endif endif