From 0ff697eb408c2045018796ad1ba13c1714a348a1 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 22 Dec 2017 10:28:31 -0500 Subject: [PATCH] Implement the "isHiddenUnder()" method for Path --- autoload/nerdtree/ui_glue.vim | 16 +++++----------- lib/nerdtree/path.vim | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index e2dc96a..e184703 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -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()) @@ -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 diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 3e7c913..b4916b4 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -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