nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 49c165a1036415e8de038d257adb3735535b6b17
parent ab0a3a7c249b46f1e180f850edbfc3b3d6ed4f60
Author: Jason Franklin <j_fra@fastmail.us>
Date:   Sat,  8 Jul 2017 10:53:05 -0400

Update the function that drives the `p` mapping

As reported in issue #67, the function driving the `p` mapping was
not updated to work as expected when the cursor is positioned on a
cascade. This problem is addressed here.

Fixes #67.

Diffstat:
Mautoload/nerdtree/ui_glue.vim | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim
@@ -404,13 +404,27 @@ function! s:jumpToLastChild(node)
 endfunction
 
 " FUNCTION: s:jumpToParent(node) {{{1
-" moves the cursor to the parent of the current node
+" Move the cursor to the parent of the specified node. For a cascade, move to
+" the parent of the cascade's highest node. At the root, do nothing.
 function! s:jumpToParent(node)
-    if !empty(a:node.parent)
-        call a:node.parent.putCursorHere(1, 0)
+    let l:parent = a:node.parent
+
+    " If "a:node" represents a directory, back out of its cascade.
+    if a:node.path.isDirectory
+        while !empty(l:parent) && !l:parent.isRoot()
+            if index(l:parent.getCascade(), a:node) >= 0
+                let l:parent = l:parent.parent
+            else
+                break
+            endif
+        endwhile
+    endif
+
+    if !empty(l:parent)
+        call l:parent.putCursorHere(1, 0)
         call b:NERDTree.ui.centerView()
     else
-        call nerdtree#echo("cannot jump to parent")
+        call nerdtree#echo('could not jump to parent node')
     endif
 endfunction