mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 03:43:50 -05:00
move getSelectedNode into TreeFileNode
This commit is contained in:
@@ -712,6 +712,19 @@ function! s:TreeFileNode.GetRootLineNum()
|
|||||||
return rootLine
|
return rootLine
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: TreeFileNode.GetSelected() {{{3
|
||||||
|
"gets the treenode that the cursor is currently over
|
||||||
|
function! s:TreeFileNode.GetSelected()
|
||||||
|
try
|
||||||
|
let path = s:getPath(line("."))
|
||||||
|
if path == {}
|
||||||
|
return {}
|
||||||
|
endif
|
||||||
|
return b:NERDTreeRoot.findNode(path)
|
||||||
|
catch /NERDTree/
|
||||||
|
return {}
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
"FUNCTION: TreeFileNode.isVisible() {{{3
|
"FUNCTION: TreeFileNode.isVisible() {{{3
|
||||||
"returns 1 if this node should be visible according to the tree filters and
|
"returns 1 if this node should be visible according to the tree filters and
|
||||||
"hidden file filters (and their on/off status)
|
"hidden file filters (and their on/off status)
|
||||||
@@ -1085,6 +1098,19 @@ function! s:TreeDirNode.getChildIndex(path)
|
|||||||
return -1
|
return -1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: TreeDirNode.GetSelected() {{{3
|
||||||
|
"Returns the current node if it is a dir node, or else returns the current
|
||||||
|
"nodes parent
|
||||||
|
unlet s:TreeDirNode.GetSelected
|
||||||
|
function! s:TreeDirNode.GetSelected()
|
||||||
|
let currentDir = s:TreeFileNode.GetSelected()
|
||||||
|
if currentDir != {} && !currentDir.isRoot()
|
||||||
|
if currentDir.path.isDirectory == 0
|
||||||
|
let currentDir = currentDir.parent
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
return currentDir
|
||||||
|
endfunction
|
||||||
"FUNCTION: TreeDirNode.getVisibleChildCount() {{{3
|
"FUNCTION: TreeDirNode.getVisibleChildCount() {{{3
|
||||||
"Returns the number of visible children this node has
|
"Returns the number of visible children this node has
|
||||||
function! s:TreeDirNode.getVisibleChildCount()
|
function! s:TreeDirNode.getVisibleChildCount()
|
||||||
@@ -2196,7 +2222,7 @@ function! NERDTreeGetCurrentNode()
|
|||||||
call s:putCursorInTreeWin()
|
call s:putCursorInTreeWin()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
|
|
||||||
if winnr != winnr()
|
if winnr != winnr()
|
||||||
call s:exec('wincmd w')
|
call s:exec('wincmd w')
|
||||||
@@ -2523,31 +2549,6 @@ function! s:getSelectedBookmark()
|
|||||||
return {}
|
return {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: s:getSelectedDir() {{{2
|
|
||||||
"Returns the current node if it is a dir node, or else returns the current
|
|
||||||
"nodes parent
|
|
||||||
function! s:getSelectedDir()
|
|
||||||
let currentDir = s:getSelectedNode()
|
|
||||||
if currentDir != {} && !currentDir.isRoot()
|
|
||||||
if currentDir.path.isDirectory == 0
|
|
||||||
let currentDir = currentDir.parent
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
return currentDir
|
|
||||||
endfunction
|
|
||||||
"FUNCTION: s:getSelectedNode() {{{2
|
|
||||||
"gets the treenode that the cursor is currently over
|
|
||||||
function! s:getSelectedNode()
|
|
||||||
try
|
|
||||||
let path = s:getPath(line("."))
|
|
||||||
if path == {}
|
|
||||||
return {}
|
|
||||||
endif
|
|
||||||
return b:NERDTreeRoot.findNode(path)
|
|
||||||
catch /NERDTree/
|
|
||||||
return {}
|
|
||||||
endtry
|
|
||||||
endfunction
|
|
||||||
"FUNCTION: s:getTreeWinNum() {{{2
|
"FUNCTION: s:getTreeWinNum() {{{2
|
||||||
"gets the nerd tree window number for this tab
|
"gets the nerd tree window number for this tab
|
||||||
function! s:getTreeWinNum()
|
function! s:getTreeWinNum()
|
||||||
@@ -2600,7 +2601,7 @@ endfunction
|
|||||||
" Args:
|
" Args:
|
||||||
" direction: 0 if going to first child, 1 if going to last
|
" direction: 0 if going to first child, 1 if going to last
|
||||||
function! s:jumpToChild(direction)
|
function! s:jumpToChild(direction)
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if currentNode == {} || currentNode.isRoot()
|
if currentNode == {} || currentNode.isRoot()
|
||||||
call s:echo("cannot jump to " . (a:direction ? "last" : "first") . " child")
|
call s:echo("cannot jump to " . (a:direction ? "last" : "first") . " child")
|
||||||
return
|
return
|
||||||
@@ -2741,7 +2742,7 @@ endfunction
|
|||||||
"Renders the tree and ensures the cursor stays on the current node or the
|
"Renders the tree and ensures the cursor stays on the current node or the
|
||||||
"current nodes parent if it is no longer available upon re-rendering
|
"current nodes parent if it is no longer available upon re-rendering
|
||||||
function! s:renderViewSavingPosition()
|
function! s:renderViewSavingPosition()
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
|
|
||||||
"go up the tree till we find a node that will be visible or till we run
|
"go up the tree till we find a node that will be visible or till we run
|
||||||
"out of nodes
|
"out of nodes
|
||||||
@@ -2950,7 +2951,7 @@ function! s:activateNode(forceKeepWindowOpen)
|
|||||||
return s:upDir(0)
|
return s:upDir(0)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode != {}
|
if treenode != {}
|
||||||
if treenode.path.isDirectory
|
if treenode.path.isDirectory
|
||||||
call treenode.toggleOpen()
|
call treenode.toggleOpen()
|
||||||
@@ -3043,7 +3044,7 @@ endfunction
|
|||||||
" FUNCTION: s:bookmarkNode(name) {{{2
|
" FUNCTION: s:bookmarkNode(name) {{{2
|
||||||
" Associate the current node with the given name
|
" Associate the current node with the given name
|
||||||
function! s:bookmarkNode(name)
|
function! s:bookmarkNode(name)
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if currentNode != {}
|
if currentNode != {}
|
||||||
try
|
try
|
||||||
call currentNode.bookmark(a:name)
|
call currentNode.bookmark(a:name)
|
||||||
@@ -3060,7 +3061,7 @@ endfunction
|
|||||||
"called (directories are automatically opened if the symbol beside them is
|
"called (directories are automatically opened if the symbol beside them is
|
||||||
"clicked)
|
"clicked)
|
||||||
function! s:checkForActivate()
|
function! s:checkForActivate()
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if currentNode != {}
|
if currentNode != {}
|
||||||
let startToCur = strpart(getline(line(".")), 0, col("."))
|
let startToCur = strpart(getline(line(".")), 0, col("."))
|
||||||
let char = strpart(startToCur, strlen(startToCur)-1, 1)
|
let char = strpart(startToCur, strlen(startToCur)-1, 1)
|
||||||
@@ -3085,7 +3086,7 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: s:chCwd() {{{2
|
" FUNCTION: s:chCwd() {{{2
|
||||||
function! s:chCwd()
|
function! s:chCwd()
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode == {}
|
if treenode == {}
|
||||||
call s:echo("Select a node first")
|
call s:echo("Select a node first")
|
||||||
return
|
return
|
||||||
@@ -3101,7 +3102,7 @@ endfunction
|
|||||||
" FUNCTION: s:chRoot() {{{2
|
" FUNCTION: s:chRoot() {{{2
|
||||||
" changes the current root to the selected one
|
" changes the current root to the selected one
|
||||||
function! s:chRoot()
|
function! s:chRoot()
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode == {}
|
if treenode == {}
|
||||||
call s:echo("Select a node first")
|
call s:echo("Select a node first")
|
||||||
return
|
return
|
||||||
@@ -3115,7 +3116,7 @@ endfunction
|
|||||||
" FUNCTION: s:clearBookmarks(bookmarks) {{{2
|
" FUNCTION: s:clearBookmarks(bookmarks) {{{2
|
||||||
function! s:clearBookmarks(bookmarks)
|
function! s:clearBookmarks(bookmarks)
|
||||||
if a:bookmarks == ''
|
if a:bookmarks == ''
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if currentNode != {}
|
if currentNode != {}
|
||||||
call currentNode.clearBoomarks()
|
call currentNode.clearBoomarks()
|
||||||
endif
|
endif
|
||||||
@@ -3143,7 +3144,7 @@ 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
|
||||||
function! s:closeCurrentDir()
|
function! s:closeCurrentDir()
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode == {}
|
if treenode == {}
|
||||||
call s:echo("Select a node first")
|
call s:echo("Select a node first")
|
||||||
return
|
return
|
||||||
@@ -3161,7 +3162,7 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: s:copyNode() {{{2
|
" FUNCTION: s:copyNode() {{{2
|
||||||
function! s:copyNode()
|
function! s:copyNode()
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if currentNode == {}
|
if currentNode == {}
|
||||||
call s:echo("Put the cursor on a file node first")
|
call s:echo("Put the cursor on a file node first")
|
||||||
return
|
return
|
||||||
@@ -3227,7 +3228,7 @@ endfunction
|
|||||||
" if the current node is a file, pops up a dialog giving the user the option
|
" if the current node is a file, pops up a dialog giving the user the option
|
||||||
" to delete it
|
" to delete it
|
||||||
function! s:deleteNode()
|
function! s:deleteNode()
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if currentNode == {}
|
if currentNode == {}
|
||||||
call s:echo("Put the cursor on a file node first")
|
call s:echo("Put the cursor on a file node first")
|
||||||
return
|
return
|
||||||
@@ -3284,7 +3285,7 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: s:executeNode() {{{2
|
" FUNCTION: s:executeNode() {{{2
|
||||||
function! s:executeNode()
|
function! s:executeNode()
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode == {} || treenode.path.isDirectory
|
if treenode == {} || treenode.path.isDirectory
|
||||||
call s:echo("Select an executable file node first" )
|
call s:echo("Select an executable file node first" )
|
||||||
else
|
else
|
||||||
@@ -3304,7 +3305,7 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: s:handleMiddleMouse() {{{2
|
" FUNCTION: s:handleMiddleMouse() {{{2
|
||||||
function! s:handleMiddleMouse()
|
function! s:handleMiddleMouse()
|
||||||
let curNode = s:getSelectedNode()
|
let curNode = s:TreeFileNode.GetSelected()
|
||||||
if curNode == {}
|
if curNode == {}
|
||||||
call s:echo("Put the cursor on a node first" )
|
call s:echo("Put the cursor on a node first" )
|
||||||
return
|
return
|
||||||
@@ -3367,7 +3368,7 @@ endfunction
|
|||||||
" FUNCTION: s:jumpToParent() {{{2
|
" FUNCTION: s:jumpToParent() {{{2
|
||||||
" moves the cursor to the parent of the current node
|
" moves the cursor to the parent of the current node
|
||||||
function! s:jumpToParent()
|
function! s:jumpToParent()
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if !empty(currentNode)
|
if !empty(currentNode)
|
||||||
if !empty(currentNode.parent)
|
if !empty(currentNode.parent)
|
||||||
call currentNode.parent.putCursorHere(1, 0)
|
call currentNode.parent.putCursorHere(1, 0)
|
||||||
@@ -3394,7 +3395,7 @@ endfunction
|
|||||||
" forward: 1 if the cursor should move to the next sibling, 0 if it should
|
" forward: 1 if the cursor should move to the next sibling, 0 if it should
|
||||||
" move back to the previous sibling
|
" move back to the previous sibling
|
||||||
function! s:jumpToSibling(forward)
|
function! s:jumpToSibling(forward)
|
||||||
let currentNode = s:getSelectedNode()
|
let currentNode = s:TreeFileNode.GetSelected()
|
||||||
if !empty(currentNode)
|
if !empty(currentNode)
|
||||||
let sibling = currentNode.findSibling(a:forward)
|
let sibling = currentNode.findSibling(a:forward)
|
||||||
|
|
||||||
@@ -3432,7 +3433,7 @@ endfunction
|
|||||||
"args:
|
"args:
|
||||||
"forceKeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set
|
"forceKeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set
|
||||||
function! s:openEntrySplit(forceKeepWindowOpen)
|
function! s:openEntrySplit(forceKeepWindowOpen)
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode != {}
|
if treenode != {}
|
||||||
call treenode.openSplit()
|
call treenode.openSplit()
|
||||||
if !a:forceKeepWindowOpen
|
if !a:forceKeepWindowOpen
|
||||||
@@ -3461,7 +3462,7 @@ endfunction
|
|||||||
function! s:openInNewTab(stayCurrentTab)
|
function! s:openInNewTab(stayCurrentTab)
|
||||||
let currentTab = tabpagenr()
|
let currentTab = tabpagenr()
|
||||||
|
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode != {}
|
if treenode != {}
|
||||||
if treenode.path.isDirectory
|
if treenode.path.isDirectory
|
||||||
tabnew
|
tabnew
|
||||||
@@ -3487,7 +3488,7 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: s:openNodeRecursively() {{{2
|
" FUNCTION: s:openNodeRecursively() {{{2
|
||||||
function! s:openNodeRecursively()
|
function! s:openNodeRecursively()
|
||||||
let treenode = s:getSelectedNode()
|
let treenode = s:TreeFileNode.GetSelected()
|
||||||
if treenode == {} || treenode.path.isDirectory == 0
|
if treenode == {} || treenode.path.isDirectory == 0
|
||||||
call s:echo("Select a directory node first" )
|
call s:echo("Select a directory node first" )
|
||||||
else
|
else
|
||||||
@@ -3550,7 +3551,7 @@ endfunction
|
|||||||
" FUNCTION: s:renameCurrent() {{{2
|
" FUNCTION: s:renameCurrent() {{{2
|
||||||
" allows the user to rename the current node
|
" allows the user to rename the current node
|
||||||
function! s:renameCurrent()
|
function! s:renameCurrent()
|
||||||
let curNode = s:getSelectedNode()
|
let curNode = s:TreeFileNode.GetSelected()
|
||||||
if curNode == {}
|
if curNode == {}
|
||||||
call s:echo("Put the cursor on a node first" )
|
call s:echo("Put the cursor on a node first" )
|
||||||
return
|
return
|
||||||
@@ -3589,7 +3590,7 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: s:showFileSystemMenu() {{{2
|
" FUNCTION: s:showFileSystemMenu() {{{2
|
||||||
function! s:showFileSystemMenu()
|
function! s:showFileSystemMenu()
|
||||||
let curNode = s:getSelectedNode()
|
let curNode = s:TreeFileNode.GetSelected()
|
||||||
if curNode == {}
|
if curNode == {}
|
||||||
call s:echo("Put the cursor on a node first" )
|
call s:echo("Put the cursor on a node first" )
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user