mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 11:53:48 -05:00
make cascading dirs more compact
Render cascading dirs on one line i.e.
> foo/bar/baz
file1
instead of
> foo
> bar
> baz
> file1
This should be useful things like java projects that have deep dir
structures.
Remove the old UI view (pre the dir arrows) as this simply isnt worth
supporting for a proof of concept. This may get added back - or not.
This commit is contained in:
@@ -73,6 +73,24 @@ function! s:TreeDirNode.createChild(path, inOrder)
|
|||||||
return newTreeNode
|
return newTreeNode
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: TreeDirNode.displayString() {{{1
|
||||||
|
unlet s:TreeDirNode.displayString
|
||||||
|
function! s:TreeDirNode.displayString()
|
||||||
|
let vc = self.getVisibleChildren()
|
||||||
|
if len(vc) != 1
|
||||||
|
return self.path.displayString()
|
||||||
|
endif
|
||||||
|
|
||||||
|
let visChild = vc[0]
|
||||||
|
|
||||||
|
"TODO: optimize
|
||||||
|
if !visChild.path.isDirectory
|
||||||
|
return self.path.displayString()
|
||||||
|
endif
|
||||||
|
|
||||||
|
return self.path.getLastPathComponent(1) . visChild.displayString()
|
||||||
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.findNode(path) {{{1
|
"FUNCTION: TreeDirNode.findNode(path) {{{1
|
||||||
"Will find one of the children (recursively) that has the given path
|
"Will find one of the children (recursively) that has the given path
|
||||||
"
|
"
|
||||||
@@ -218,6 +236,13 @@ function! s:TreeDirNode.hasVisibleChildren()
|
|||||||
return self.getVisibleChildCount() != 0
|
return self.getVisibleChildCount() != 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: TreeDirNode.isCascadable() {{{1
|
||||||
|
"true if this dir has only one visible child - which is also a dir
|
||||||
|
function! s:TreeDirNode.isCascadable()
|
||||||
|
let c = self.getVisibleChildren()
|
||||||
|
return len(c) == 1 && c[0].path.isDirectory
|
||||||
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode._initChildren() {{{1
|
"FUNCTION: TreeDirNode._initChildren() {{{1
|
||||||
"Removes all childen from this node and re-reads them
|
"Removes all childen from this node and re-reads them
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -323,70 +323,27 @@ endfunction
|
|||||||
"FUNCTION: TreeFileNode.renderToString {{{1
|
"FUNCTION: TreeFileNode.renderToString {{{1
|
||||||
"returns a string representation for this tree to be rendered in the view
|
"returns a string representation for this tree to be rendered in the view
|
||||||
function! s:TreeFileNode.renderToString()
|
function! s:TreeFileNode.renderToString()
|
||||||
return self._renderToString(0, 0, [], self.getChildCount() ==# 1)
|
return self._renderToString(0, 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"Args:
|
"Args:
|
||||||
"depth: the current depth in the tree for this call
|
"depth: the current depth in the tree for this call
|
||||||
"drawText: 1 if we should actually draw the line for this node (if 0 then the
|
"drawText: 1 if we should actually draw the line for this node (if 0 then the
|
||||||
"child nodes are rendered only)
|
"child nodes are rendered only)
|
||||||
"vertMap: a binary array that indicates whether a vertical bar should be draw
|
|
||||||
"for each depth in the tree
|
"for each depth in the tree
|
||||||
"isLastChild:true if this curNode is the last child of its parent
|
function! s:TreeFileNode._renderToString(depth, drawText)
|
||||||
function! s:TreeFileNode._renderToString(depth, drawText, vertMap, isLastChild)
|
|
||||||
let output = ""
|
let output = ""
|
||||||
if a:drawText ==# 1
|
if a:drawText ==# 1
|
||||||
|
|
||||||
let treeParts = ''
|
let treeParts = repeat(' ', a:depth - 1)
|
||||||
|
|
||||||
"get all the leading spaces and vertical tree parts for this line
|
|
||||||
if a:depth > 1
|
|
||||||
for j in a:vertMap[0:-2]
|
|
||||||
if g:NERDTreeDirArrows
|
|
||||||
let treeParts = treeParts . ' '
|
|
||||||
else
|
|
||||||
if j ==# 1
|
|
||||||
let treeParts = treeParts . '| '
|
|
||||||
else
|
|
||||||
let treeParts = treeParts . ' '
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
|
|
||||||
"get the last vertical tree part for this line which will be different
|
|
||||||
"if this node is the last child of its parent
|
|
||||||
if !g:NERDTreeDirArrows
|
|
||||||
if a:isLastChild
|
|
||||||
let treeParts = treeParts . '`'
|
|
||||||
else
|
|
||||||
let treeParts = treeParts . '|'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
"smack the appropriate dir/file symbol on the line before the file/dir
|
|
||||||
"name itself
|
|
||||||
if self.path.isDirectory
|
if self.path.isDirectory
|
||||||
if self.isOpen
|
let sym = self.isOpen ? g:NERDTreeDirArrowCollapsible : g:NERDTreeDirArrowExpandable
|
||||||
if g:NERDTreeDirArrows
|
let treeParts = treeParts . sym . ' '
|
||||||
let treeParts = treeParts . g:NERDTreeDirArrowCollapsible . ' '
|
|
||||||
else
|
|
||||||
let treeParts = treeParts . '~'
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if g:NERDTreeDirArrows
|
|
||||||
let treeParts = treeParts . g:NERDTreeDirArrowExpandable . ' '
|
|
||||||
else
|
|
||||||
let treeParts = treeParts . '+'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
if g:NERDTreeDirArrows
|
let treeParts = treeParts . ' '
|
||||||
let treeParts = treeParts . ' '
|
|
||||||
else
|
|
||||||
let treeParts = treeParts . '-'
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let line = treeParts . self.displayString()
|
let line = treeParts . self.displayString()
|
||||||
|
|
||||||
let output = output . line . "\n"
|
let output = output . line . "\n"
|
||||||
@@ -396,18 +353,15 @@ function! s:TreeFileNode._renderToString(depth, drawText, vertMap, isLastChild)
|
|||||||
if self.path.isDirectory ==# 1 && self.isOpen ==# 1
|
if self.path.isDirectory ==# 1 && self.isOpen ==# 1
|
||||||
|
|
||||||
let childNodesToDraw = self.getVisibleChildren()
|
let childNodesToDraw = self.getVisibleChildren()
|
||||||
if len(childNodesToDraw) > 0
|
|
||||||
|
|
||||||
"draw all the nodes children except the last
|
if self.isCascadable() && a:depth > 0
|
||||||
let lastIndx = len(childNodesToDraw)-1
|
|
||||||
if lastIndx > 0
|
|
||||||
for i in childNodesToDraw[0:lastIndx-1]
|
|
||||||
let output = output . i._renderToString(a:depth + 1, 1, add(copy(a:vertMap), 1), 0)
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
|
|
||||||
"draw the last child, indicating that it IS the last
|
let output = output . childNodesToDraw[0]._renderToString(a:depth, 0)
|
||||||
let output = output . childNodesToDraw[lastIndx]._renderToString(a:depth + 1, 1, add(copy(a:vertMap), 0), 1)
|
|
||||||
|
elseif len(childNodesToDraw) > 0
|
||||||
|
for i in childNodesToDraw
|
||||||
|
let output = output . i._renderToString(a:depth + 1, 1)
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user