Skip to content

Commit 3f328b4

Browse files
author
Jason Franklin
committed
Fix unstable behavior in "NERDTreeUI.getPath()"
This commit prevents "NERDTreeUI.getPath()" from returning a "Path" object even when no tree node was selected. Previously, positioning your cursor on one of the blank lines above the tree and running... :echo g:NERDTreeFileNode.GetSelected() ... could potentially return the path for the current working directory (your working directory needs to be under the tree root). This is because the constructor for "Path" objects returns a "Path" for the current working directory when passed an empty string. So, we need to short circuit the "getPath()" function for lines that cannot possibly be tree nodes. This solves the problem for "GetSelected()" because that method uses the "getPath()" method from the "UI" class to do its work.
1 parent 1d14961 commit 3f328b4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/nerdtree/ui.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ function! s:UI.getPath(ln)
158158
return self.nerdtree.root.path.getParent()
159159
endif
160160

161+
if a:ln < rootLine
162+
return {}
163+
endif
164+
161165
let indent = self._indentLevelFor(line)
162166

163167
" remove the tree parts and the leading space

0 commit comments

Comments
 (0)