Fix the <C-J>, <C-K>, J, and K default mappings (#886)

These mappings currently fail on cascades.  This pull request fixes
this problem.
This commit is contained in:
Jason Franklin
2018-09-15 10:18:09 -04:00
committed by Jason Franklin
parent e9d3f72d9c
commit cd1f2c803e
3 changed files with 97 additions and 111 deletions

View File

@@ -153,6 +153,32 @@ function! s:TreeDirNode.getCascade()
return [self] + visChild.getCascade()
endfunction
" FUNCTION: TreeDirNode.getCascadeRoot() {{{1
" Return the first directory node in the cascade in which this directory node
" is rendered.
function! s:TreeDirNode.getCascadeRoot()
" Don't search above the current NERDTree root node.
if self.isRoot()
return self
endif
let l:cascadeRoot = self
let l:parent = self.parent
while !empty(l:parent) && !l:parent.isRoot()
if index(l:parent.getCascade(), self) == -1
break
endif
let l:cascadeRoot = l:parent
let l:parent = l:parent.parent
endwhile
return l:cascadeRoot
endfunction
" FUNCTION: TreeDirNode.getChildCount() {{{1
" Returns the number of children this node has
function! s:TreeDirNode.getChildCount()

View File

@@ -116,68 +116,40 @@ function! s:TreeFileNode.findNode(path)
return {}
endfunction
" FUNCTION: TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction) {{{1
"
" Finds the next sibling for this node in the indicated direction. This sibling
" must be a directory and may/may not have children as specified.
"
" Args:
" direction: 0 if you want to find the previous sibling, 1 for the next sibling
"
" Return:
" a treenode object or {} if no appropriate sibling could be found
function! s:TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction)
" if we have no parent then we can have no siblings
if self.parent != {}
let nextSibling = self.findSibling(a:direction)
while nextSibling != {}
if nextSibling.path.isDirectory && nextSibling.hasVisibleChildren() && nextSibling.isOpen
return nextSibling
endif
let nextSibling = nextSibling.findSibling(a:direction)
endwhile
endif
return {}
endfunction
" FUNCTION: TreeFileNode.findSibling(direction) {{{1
"
" Finds the next sibling for this node in the indicated direction
" Find the next or previous sibling of this node.
"
" Args:
" direction: 0 if you want to find the previous sibling, 1 for the next sibling
" direction: 0 for previous, 1 for next
"
" Return:
" a treenode object or {} if no sibling could be found
" The next/previous TreeFileNode object or an empty dictionary if not found.
function! s:TreeFileNode.findSibling(direction)
" if we have no parent then we can have no siblings
if self.parent != {}
" get the index of this node in its parents children
let siblingIndx = self.parent.getChildIndex(self.path)
if siblingIndx != -1
" move a long to the next potential sibling node
let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1
" keep moving along to the next sibling till we find one that is valid
let numSiblings = self.parent.getChildCount()
while siblingIndx >= 0 && siblingIndx < numSiblings
" if the next node is not an ignored node (i.e. wont show up in the
" view) then return it
if self.parent.children[siblingIndx].path.ignore(self.getNerdtree()) ==# 0
return self.parent.children[siblingIndx]
endif
" go to next node
let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1
endwhile
endif
" There can be no siblings if there is no parent.
if empty(self.parent)
return {}
endif
let l:nodeIndex = self.parent.getChildIndex(self.path)
if l:nodeIndex == -1
return {}
endif
" Get the next index to begin the search.
let l:nodeIndex += a:direction ? 1 : -1
while 0 <= l:nodeIndex && l:nodeIndex < self.parent.getChildCount()
" Return the next node if it is not ignored.
if !self.parent.children[l:nodeIndex].path.ignore(self.getNerdtree())
return self.parent.children[l:nodeIndex]
endif
let l:nodeIndex += a:direction ? 1 : -1
endwhile
return {}
endfunction