mirror of
https://github.com/preservim/nerdtree.git
synced 2024-12-01 14:43:44 +08:00
Refactor and re-document Bookmark.getNode()
A few minor changes were made to the "Bookmark.getNode()" function for the purposes of improving readability and documentation clarity. This process also led me to the conclusion that the "findNode()" function should be refactored to throw an error if a node cannot be found. This would lead to greater uniformity in the reporting of failures to find a node. It is generally better style to have an error thrown as close to the source as possible. A substantial change like this should wait for now.
This commit is contained in:
parent
c0b90811b0
commit
a03a639390
|
@ -157,18 +157,23 @@ function! s:Bookmark.delete()
|
|||
endfunction
|
||||
|
||||
" FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1
|
||||
" Gets the treenode for this bookmark
|
||||
" Returns the tree node object associated with this Bookmark.
|
||||
" Throws "NERDTree.BookmarkedNodeNotFoundError" if the node is not found.
|
||||
"
|
||||
" Args:
|
||||
" searchFromAbsoluteRoot: specifies whether we should search from the current
|
||||
" tree root, or the highest cached node
|
||||
" searchFromAbsoluteRoot: boolean flag, search from the highest cached node
|
||||
" if true and from the current tree root if false
|
||||
function! s:Bookmark.getNode(nerdtree, searchFromAbsoluteRoot)
|
||||
let searchRoot = a:searchFromAbsoluteRoot ? a:nerdtree.root.AbsoluteTreeRoot() : a:nerdtree.root
|
||||
let targetNode = searchRoot.findNode(self.path)
|
||||
if empty(targetNode)
|
||||
throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name
|
||||
if a:searchFromAbsoluteRoot
|
||||
let l:searchRoot = a:nerdtree.root.AbsoluteTreeRoot()
|
||||
else
|
||||
let l:searchRoot = a:nerdtree.root
|
||||
endif
|
||||
return targetNode
|
||||
let l:targetNode = l:searchRoot.findNode(self.path)
|
||||
if empty(l:targetNode)
|
||||
throw 'NERDTree.BookmarkedNodeNotFoundError: node for bookmark "' . self.name . '" not found'
|
||||
endif
|
||||
return l:targetNode
|
||||
endfunction
|
||||
|
||||
" FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot, nerdtree) {{{1
|
||||
|
|
Loading…
Reference in New Issue
Block a user