mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 03:43:50 -05:00
add recurseUpward arg to s:PutCursorOnNode
makes it attempt to put the cursor on the treenodes parent (recursively) if the target node is hidden
This commit is contained in:
@@ -1886,7 +1886,7 @@ function! s:JumpToChild(direction)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:PutCursorOnNode(targetNode, 1)
|
call s:PutCursorOnNode(targetNode, 1, 0)
|
||||||
|
|
||||||
call s:CenterView()
|
call s:CenterView()
|
||||||
endfunction
|
endfunction
|
||||||
@@ -2042,19 +2042,25 @@ function! s:PromptToDelBuffer(bufnum, msg)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: s:PutCursorOnNode(treenode, is_jump){{{2
|
"FUNCTION: s:PutCursorOnNode(treenode, isJump, recurseUpward){{{2
|
||||||
"Places the cursor on the line number representing the given node
|
"Places the cursor on the line number representing the given node
|
||||||
"
|
"
|
||||||
"Args:
|
"Args:
|
||||||
"treenode: the node to put the cursor on
|
"treenode: the node to put the cursor on
|
||||||
"is_jump: 1 if this cursor movement should be counted as a jump by vim
|
"isJump: 1 if this cursor movement should be counted as a jump by vim
|
||||||
function! s:PutCursorOnNode(treenode, is_jump)
|
"recurseUpward: try to put the cursor on the parent if the this node isnt
|
||||||
|
"visible
|
||||||
|
function! s:PutCursorOnNode(treenode, isJump, recurseUpward)
|
||||||
let ln = s:FindNodeLineNumber(a:treenode)
|
let ln = s:FindNodeLineNumber(a:treenode)
|
||||||
if ln != -1
|
if ln != -1
|
||||||
if a:is_jump
|
if a:isJump
|
||||||
mark '
|
mark '
|
||||||
endif
|
endif
|
||||||
call cursor(ln, col("."))
|
call cursor(ln, col("."))
|
||||||
|
else
|
||||||
|
if a:recurseUpward && a:treenode.parent != {}
|
||||||
|
call s:PutCursorOnNode(a:treenode.parent, a:isJump, 1)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -2133,7 +2139,7 @@ function! s:RenderViewSavingPosition()
|
|||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
|
|
||||||
if currentNode != {}
|
if currentNode != {}
|
||||||
call s:PutCursorOnNode(currentNode, 0)
|
call s:PutCursorOnNode(currentNode, 0, 0)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
"FUNCTION: s:RestoreScreenState() {{{2
|
"FUNCTION: s:RestoreScreenState() {{{2
|
||||||
@@ -2323,7 +2329,7 @@ function! s:ActivateNode()
|
|||||||
if treenode.path.isDirectory
|
if treenode.path.isDirectory
|
||||||
call treenode.ToggleOpen()
|
call treenode.ToggleOpen()
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(treenode, 0)
|
call s:PutCursorOnNode(treenode, 0, 0)
|
||||||
else
|
else
|
||||||
call s:OpenFileNode(treenode)
|
call s:OpenFileNode(treenode)
|
||||||
endif
|
endif
|
||||||
@@ -2447,7 +2453,7 @@ function! s:ChRoot()
|
|||||||
|
|
||||||
|
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(t:NERDTreeRoot, 0)
|
call s:PutCursorOnNode(t:NERDTreeRoot, 0, 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: s:CloseChildren() {{{2
|
" FUNCTION: s:CloseChildren() {{{2
|
||||||
@@ -2461,7 +2467,7 @@ function! s:CloseChildren()
|
|||||||
|
|
||||||
call currentNode.CloseChildren()
|
call currentNode.CloseChildren()
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(currentNode, 0)
|
call s:PutCursorOnNode(currentNode, 0, 0)
|
||||||
endfunction
|
endfunction
|
||||||
" FUNCTION: s:CloseCurrentDir() {{{2
|
" FUNCTION: s:CloseCurrentDir() {{{2
|
||||||
" closes the parent dir of the current node
|
" closes the parent dir of the current node
|
||||||
@@ -2478,7 +2484,7 @@ function! s:CloseCurrentDir()
|
|||||||
else
|
else
|
||||||
call treenode.parent.Close()
|
call treenode.parent.Close()
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(treenode.parent, 0)
|
call s:PutCursorOnNode(treenode.parent, 0, 0)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -2510,7 +2516,7 @@ function! s:CopyNode()
|
|||||||
try
|
try
|
||||||
let newNode = currentNode.Copy(newNodePath)
|
let newNode = currentNode.Copy(newNodePath)
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(newNode, 0)
|
call s:PutCursorOnNode(newNode, 0, 0)
|
||||||
catch /^NERDTree/
|
catch /^NERDTree/
|
||||||
call s:EchoWarning("Could not copy node")
|
call s:EchoWarning("Could not copy node")
|
||||||
endtry
|
endtry
|
||||||
@@ -2643,7 +2649,7 @@ function! s:InsertNewNode()
|
|||||||
if parentNode.isOpen || !empty(parentNode.children)
|
if parentNode.isOpen || !empty(parentNode.children)
|
||||||
call parentNode.AddChild(newTreeNode, 1)
|
call parentNode.AddChild(newTreeNode, 1)
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(newTreeNode, 1)
|
call s:PutCursorOnNode(newTreeNode, 1, 0)
|
||||||
endif
|
endif
|
||||||
catch /^NERDTree/
|
catch /^NERDTree/
|
||||||
call s:EchoWarning("Node Not Created.")
|
call s:EchoWarning("Node Not Created.")
|
||||||
@@ -2668,7 +2674,7 @@ function! s:JumpToParent()
|
|||||||
let currentNode = s:GetSelectedNode()
|
let currentNode = s:GetSelectedNode()
|
||||||
if !empty(currentNode)
|
if !empty(currentNode)
|
||||||
if !empty(currentNode.parent)
|
if !empty(currentNode.parent)
|
||||||
call s:PutCursorOnNode(currentNode.parent, 1)
|
call s:PutCursorOnNode(currentNode.parent, 1, 0)
|
||||||
call s:CenterView()
|
call s:CenterView()
|
||||||
else
|
else
|
||||||
call s:Echo("cannot jump to parent")
|
call s:Echo("cannot jump to parent")
|
||||||
@@ -2681,7 +2687,7 @@ endfunction
|
|||||||
" FUNCTION: s:JumpToRoot() {{{2
|
" FUNCTION: s:JumpToRoot() {{{2
|
||||||
" moves the cursor to the root node
|
" moves the cursor to the root node
|
||||||
function! s:JumpToRoot()
|
function! s:JumpToRoot()
|
||||||
call s:PutCursorOnNode(t:NERDTreeRoot, 1)
|
call s:PutCursorOnNode(t:NERDTreeRoot, 1, 0)
|
||||||
call s:CenterView()
|
call s:CenterView()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -2708,7 +2714,7 @@ function! s:JumpToSibling(forward)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if !empty(sibling)
|
if !empty(sibling)
|
||||||
call s:PutCursorOnNode(sibling, 1)
|
call s:PutCursorOnNode(sibling, 1, 0)
|
||||||
call s:CenterView()
|
call s:CenterView()
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@@ -2855,7 +2861,7 @@ function! s:RenameCurrent()
|
|||||||
call s:PromptToDelBuffer(bufnum, prompt)
|
call s:PromptToDelBuffer(bufnum, prompt)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:PutCursorOnNode(curNode, 1)
|
call s:PutCursorOnNode(curNode, 1, 0)
|
||||||
|
|
||||||
redraw
|
redraw
|
||||||
catch /^NERDTree/
|
catch /^NERDTree/
|
||||||
@@ -2952,7 +2958,7 @@ function! s:UpDir(keepState)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
call s:RenderView()
|
call s:RenderView()
|
||||||
call s:PutCursorOnNode(oldRoot, 0)
|
call s:PutCursorOnNode(oldRoot, 0, 0)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user