mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-26 18:30:45 +08:00
Merge pull request #785 from lifecrisis/find-new-file
In certain cases, ":NERDTreeFind" would fail to reveal files that were created/written after the current tab's NERDTree had been initialized. This pull request repairs that problem.
This commit is contained in:
commit
57788abd6f
|
@ -261,61 +261,55 @@ function! s:displayHelp()
|
||||||
call b:NERDTree.ui.centerView()
|
call b:NERDTree.ui.centerView()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: s:findAndRevealPath(path) {{{1
|
" FUNCTION: s:findAndRevealPath(pathStr) {{{1
|
||||||
function! s:findAndRevealPath(path)
|
function! s:findAndRevealPath(pathStr)
|
||||||
let l:path = a:path
|
let l:pathStr = !empty(a:pathStr) ? a:pathStr : expand('%:p')
|
||||||
|
|
||||||
if empty(l:path)
|
if empty(l:pathStr)
|
||||||
let l:path = expand('%:p')
|
call nerdtree#echoWarning('no file for the current buffer')
|
||||||
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
try
|
try
|
||||||
let p = g:NERDTreePath.New(l:path)
|
let l:pathObj = g:NERDTreePath.New(l:pathStr)
|
||||||
catch /^NERDTree.InvalidArgumentsError/
|
catch /^NERDTree.InvalidArgumentsError/
|
||||||
call nerdtree#echo("no file for the current buffer")
|
call nerdtree#echoWarning('invalid path')
|
||||||
return
|
return
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if p.isUnixHiddenPath()
|
if l:pathObj.isUnixHiddenPath()
|
||||||
let showhidden=g:NERDTreeShowHidden
|
let l:showHidden = g:NERDTreeShowHidden
|
||||||
let g:NERDTreeShowHidden = 1
|
let g:NERDTreeShowHidden = 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !g:NERDTree.ExistsForTab()
|
if !g:NERDTree.ExistsForTab()
|
||||||
try
|
try
|
||||||
let cwd = g:NERDTreePath.New(getcwd())
|
let l:cwd = g:NERDTreePath.New(getcwd())
|
||||||
catch /^NERDTree.InvalidArgumentsError/
|
catch /^NERDTree.InvalidArgumentsError/
|
||||||
call nerdtree#echo("current directory does not exist.")
|
call nerdtree#echo('current directory does not exist.')
|
||||||
let cwd = p.getParent()
|
let l:cwd = l:pathObj.getParent()
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if p.isUnder(cwd)
|
if l:pathObj.isUnder(l:cwd)
|
||||||
call g:NERDTreeCreator.CreateTabTree(cwd.str())
|
call g:NERDTreeCreator.CreateTabTree(l:cwd.str())
|
||||||
else
|
else
|
||||||
call g:NERDTreeCreator.CreateTabTree(p.getParent().str())
|
call g:NERDTreeCreator.CreateTabTree(l:pathObj.getParent().str())
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
|
NERDTreeFocus
|
||||||
if !g:NERDTree.IsOpen()
|
|
||||||
call g:NERDTreeCreator.ToggleTabTree('')
|
|
||||||
else
|
|
||||||
call g:NERDTree.CursorToTreeWin()
|
|
||||||
endif
|
|
||||||
call b:NERDTree.ui.setShowHidden(g:NERDTreeShowHidden)
|
|
||||||
call s:chRoot(g:NERDTreeDirNode.New(p.getParent(), b:NERDTree))
|
|
||||||
else
|
|
||||||
if !g:NERDTree.IsOpen()
|
|
||||||
call g:NERDTreeCreator.ToggleTabTree("")
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
call g:NERDTree.CursorToTreeWin()
|
|
||||||
let node = b:NERDTree.root.reveal(p)
|
|
||||||
call b:NERDTree.render()
|
|
||||||
call node.putCursorHere(1,0)
|
|
||||||
|
|
||||||
if p.isUnixHiddenFile()
|
if !l:pathObj.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
|
||||||
let g:NERDTreeShowHidden = showhidden
|
call b:NERDTree.ui.setShowHidden(g:NERDTreeShowHidden)
|
||||||
|
call s:chRoot(g:NERDTreeDirNode.New(l:pathObj.getParent(), b:NERDTree))
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:node = b:NERDTree.root.reveal(l:pathObj)
|
||||||
|
call b:NERDTree.render()
|
||||||
|
call l:node.putCursorHere(1, 0)
|
||||||
|
|
||||||
|
if l:pathObj.isUnixHiddenFile()
|
||||||
|
let g:NERDTreeShowHidden = l:showHidden
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
@ -126,20 +126,20 @@ The following features and functionality are provided by the NERD tree:
|
||||||
Changes made to one tree are reflected in both as they are actually the
|
Changes made to one tree are reflected in both as they are actually the
|
||||||
same buffer.
|
same buffer.
|
||||||
|
|
||||||
If only one other NERD tree exists, that tree is automatically mirrored. If
|
If only one other NERD tree exists, that tree is automatically mirrored.
|
||||||
more than one exists, the script will ask which tree to mirror.
|
If more than one exists, the script will ask which tree to mirror.
|
||||||
|
|
||||||
:NERDTreeClose *:NERDTreeClose*
|
:NERDTreeClose *:NERDTreeClose*
|
||||||
Close the NERD tree in this tab.
|
Close the NERD tree in this tab.
|
||||||
|
|
||||||
:NERDTreeFind *:NERDTreeFind*
|
:NERDTreeFind [<path>] *:NERDTreeFind*
|
||||||
Find the current file in the tree.
|
Without the optional argument, find and reveal the file for the active
|
||||||
|
buffer in the NERDTree window. With the <path> argument, find and
|
||||||
|
reveal the specified path.
|
||||||
|
|
||||||
If no tree exists and the current file is under vim's CWD, then init a
|
Focus will be shifted to the NERDTree window, and the cursor will be
|
||||||
tree at the CWD and reveal the file. Otherwise init a tree in the current
|
placed on the tree node for the determined path. If a NERDTree for the
|
||||||
file's directory.
|
current tab does not exist, a new one will be initialized.
|
||||||
|
|
||||||
In any case, the current file is revealed and the cursor is placed on it.
|
|
||||||
|
|
||||||
:NERDTreeCWD *:NERDTreeCWD*
|
:NERDTreeCWD *:NERDTreeCWD*
|
||||||
Change tree root to current directory. If no NERD tree exists for this
|
Change tree root to current directory. If no NERD tree exists for this
|
||||||
|
@ -1128,13 +1128,12 @@ NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()*
|
||||||
Additionally, a "scope" argument may be supplied. This constrains the
|
Additionally, a "scope" argument may be supplied. This constrains the
|
||||||
mapping so that it is only activated if the cursor is on a certain object.
|
mapping so that it is only activated if the cursor is on a certain object.
|
||||||
That object is then passed into the handling method. Possible values are:
|
That object is then passed into the handling method. Possible values are:
|
||||||
"FileNode" - a file node
|
|
||||||
"DirNode" - a directory node
|
|
||||||
"Node" - a file or directory node
|
|
||||||
"Bookmark" - A bookmark
|
|
||||||
"all" - the keymap is not constrained to any scope (default). When
|
|
||||||
thei is used, the handling function is not passed any arguments.
|
|
||||||
|
|
||||||
|
"FileNode" .... a file node
|
||||||
|
"DirNode" ..... a directory node
|
||||||
|
"Node" ........ a file node OR a directory node
|
||||||
|
"Bookmark" .... a bookmark
|
||||||
|
"all" ......... global scope; handler receives no arguments (default)
|
||||||
|
|
||||||
Example: >
|
Example: >
|
||||||
call NERDTreeAddKeyMap({
|
call NERDTreeAddKeyMap({
|
||||||
|
|
|
@ -568,6 +568,13 @@ function! s:TreeDirNode.reveal(path, ...)
|
||||||
throw "NERDTree.InvalidArgumentsError: " . a:path.str() . " should be under " . self.path.str()
|
throw "NERDTree.InvalidArgumentsError: " . a:path.str() . " should be under " . self.path.str()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Refresh "self.children" to avoid missing paths created after this node
|
||||||
|
" was last opened. If "self.children" is empty, the call to "open()" will
|
||||||
|
" initialize the children.
|
||||||
|
if !empty(self.children)
|
||||||
|
" Silence messages/errors. They were seen on the first open.
|
||||||
|
silent! call self._initChildren(1)
|
||||||
|
endif
|
||||||
call self.open()
|
call self.open()
|
||||||
|
|
||||||
if self.path.equals(a:path.getParent())
|
if self.path.equals(a:path.getParent())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user