Skip to content

Commit

Permalink
Merge pull request #786 from lifecrisis/find-hidden
Browse files Browse the repository at this point in the history
Here, a more accurate method of determining whether or not to show
hidden files is used.  A new method, "isHiddenUnder()" is defined
for "Path" objects.  This method is then used to set the flag for
hidden files in the ":NERDTreeFind" command.  Note that this
function is likely to be useful elsewhere.

Fixes #189.
  • Loading branch information
lifecrisis authored and Jason Franklin committed Jan 5, 2018
2 parents 57788ab + d90b2af commit fa65ec6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
16 changes: 5 additions & 11 deletions autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,6 @@ function! s:findAndRevealPath(pathStr)
return
endtry

if l:pathObj.isUnixHiddenPath()
let l:showHidden = g:NERDTreeShowHidden
let g:NERDTreeShowHidden = 1
endif

if !g:NERDTree.ExistsForTab()
try
let l:cwd = g:NERDTreePath.New(getcwd())
Expand All @@ -298,19 +293,18 @@ function! s:findAndRevealPath(pathStr)
else
NERDTreeFocus

if !l:pathObj.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
call b:NERDTree.ui.setShowHidden(g:NERDTreeShowHidden)
if !l:pathObj.isUnder(b:NERDTree.root.path)
call s:chRoot(g:NERDTreeDirNode.New(l:pathObj.getParent(), b:NERDTree))
endif
endif

if l:pathObj.isHiddenUnder(b:NERDTree.root.path)
call b:NERDTree.ui.setShowHidden(1)
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
endfunction

"FUNCTION: s:handleLeftClick() {{{1
Expand Down
19 changes: 19 additions & 0 deletions lib/nerdtree/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,25 @@ function! s:Path.getSortKey()
return self._sortKey
endfunction

" FUNCTION: Path.isHiddenUnder(path) {{{1
function! s:Path.isHiddenUnder(path)

if !self.isUnder(a:path)
return 0
endif

let l:startIndex = len(a:path.pathSegments)
let l:segments = self.pathSegments[l:startIndex : ]

for l:segment in l:segments

if l:segment =~# '^\.'
return 1
endif
endfor

return 0
endfunction

" FUNCTION: Path.isUnixHiddenFile() {{{1
" check for unix hidden files
Expand Down

0 comments on commit fa65ec6

Please sign in to comment.