Merge pull request #759 from lifecrisis/iss549

This pull request repairs the broken "t" and "T" mappings.
This commit is contained in:
Jason Franklin 2017-11-14 08:37:09 -05:00 committed by GitHub
commit b6e3c0db30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 96 additions and 92 deletions

View File

@ -1,4 +1,5 @@
Next Next
- Fix broken "t" and "T" mappings, tabs now open at end (lifecrisis) #759
- Update doc with already existing mapping variables (asnr) #699 - Update doc with already existing mapping variables (asnr) #699
- Fix the broken g:NERDTreeBookmarksSort setting (lifecrisis) #696 - Fix the broken g:NERDTreeBookmarksSort setting (lifecrisis) #696
- Correct NERDTreeIgnore pattern in doc (cntoplolicon) #648 - Correct NERDTreeIgnore pattern in doc (cntoplolicon) #648

View File

@ -68,10 +68,10 @@ function! nerdtree#ui_glue#createDefaultBindings()
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': "Node", 'callback': s."jumpToNextSibling" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': "Node", 'callback': s."jumpToNextSibling" })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': "Node", 'callback': s."jumpToPrevSibling" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': "Node", 'callback': s."jumpToPrevSibling" })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Node", 'callback': s."openInNewTab" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': 'Node', 'callback': s . 'openInNewTab' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Node", 'callback': s."openInNewTabSilent" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': 'Node', 'callback': s . 'openInNewTabSilent' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Bookmark", 'callback': s."openInNewTab" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': 'Bookmark', 'callback': s . 'openInNewTab' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Bookmark", 'callback': s."openInNewTabSilent" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': 'Bookmark', 'callback': s . 'openInNewTabSilent' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenExpl, 'scope': "DirNode", 'callback': s."openExplorer" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenExpl, 'scope': "DirNode", 'callback': s."openExplorer" })
@ -494,12 +494,14 @@ endfunction
" FUNCTION: s:openInNewTab(target) {{{1 " FUNCTION: s:openInNewTab(target) {{{1
function! s:openInNewTab(target) function! s:openInNewTab(target)
call a:target.activate({'where': 't'}) let l:opener = g:NERDTreeOpener.New(a:target.path, {'where': 't'})
call l:opener.open(a:target)
endfunction endfunction
" FUNCTION: s:openInNewTabSilent(target) {{{1 " FUNCTION: s:openInNewTabSilent(target) {{{1
function! s:openInNewTabSilent(target) function! s:openInNewTabSilent(target)
call a:target.activate({'where': 't', 'stay': 1}) let l:opener = g:NERDTreeOpener.New(a:target.path, {'where': 't', 'stay': 1})
call l:opener.open(a:target)
endfunction endfunction
" FUNCTION: s:openNodeRecursively(node) {{{1 " FUNCTION: s:openNodeRecursively(node) {{{1

View File

@ -1,7 +1,13 @@
" ============================================================================
" CLASS: Creator " CLASS: Creator
"Creates tab/window/mirror nerdtree windows. Sets up all the window and "
"buffer options and key mappings etc. " This class is responsible for creating NERDTree instances. The new NERDTree
"============================================================ " may be a tab tree, a window tree, or a mirrored tree. In the process of
" creating a NERDTree, it sets up all of the window and buffer options and key
" mappings etc.
" ============================================================================
let s:Creator = {} let s:Creator = {}
let g:NERDTreeCreator = s:Creator let g:NERDTreeCreator = s:Creator
@ -41,33 +47,26 @@ endfunction
" FUNCTION: s:Creator.createTabTree(a:name) {{{1 " FUNCTION: s:Creator.createTabTree(a:name) {{{1
" name: the name of a bookmark or a directory " name: the name of a bookmark or a directory
function! s:Creator.createTabTree(name) function! s:Creator.createTabTree(name)
let path = self._pathForString(a:name) let l:path = self._pathForString(a:name)
"abort if exception was thrown (bookmark/dir doesn't exist) " Abort if an exception was thrown (i.e., if the bookmark or directory
if empty(path) " does not exist).
if empty(l:path)
return return
endif endif
if path == {} " Obey the user's preferences for changing the working directory.
return
endif
"if instructed to, then change the vim CWD to the dir the NERDTree is
"inited in
if g:NERDTreeChDirMode != 0 if g:NERDTreeChDirMode != 0
call path.changeToDir() call l:path.changeToDir()
endif endif
if g:NERDTree.ExistsForTab() if g:NERDTree.ExistsForTab()
if g:NERDTree.IsOpen()
call g:NERDTree.Close() call g:NERDTree.Close()
endif
call self._removeTreeBufForTab() call self._removeTreeBufForTab()
endif endif
call self._createTreeWin() call self._createTreeWin()
call self._createNERDTree(path, "tab") call self._createNERDTree(l:path, 'tab')
call b:NERDTree.render() call b:NERDTree.render()
call b:NERDTree.root.putCursorHere(0, 0) call b:NERDTree.root.putCursorHere(0, 0)
@ -110,11 +109,6 @@ endfunction
" FUNCTION: s:Creator._createNERDTree(path) {{{1 " FUNCTION: s:Creator._createNERDTree(path) {{{1
function! s:Creator._createNERDTree(path, type) function! s:Creator._createNERDTree(path, type)
let b:NERDTree = g:NERDTree.New(a:path, a:type) let b:NERDTree = g:NERDTree.New(a:path, a:type)
"TODO: This is kept for compatability only since many things use
"b:NERDTreeRoot instead of the new NERDTree.root
"Remove this one day
let b:NERDTreeRoot = b:NERDTree.root
call b:NERDTree.root.open() call b:NERDTree.root.open()
endfunction endfunction

View File

@ -75,7 +75,7 @@ function! s:Opener._gotoTargetWin()
elseif self._where == 'h' elseif self._where == 'h'
split split
elseif self._where == 't' elseif self._where == 't'
tabnew $tabnew
endif endif
else else
call self._checkToCloseTree(1) call self._checkToCloseTree(1)
@ -85,7 +85,7 @@ function! s:Opener._gotoTargetWin()
elseif self._where == 'h' elseif self._where == 'h'
call self._newSplit() call self._newSplit()
elseif self._where == 't' elseif self._where == 't'
tabnew $tabnew
elseif self._where == 'p' elseif self._where == 'p'
call self._previousWindow() call self._previousWindow()
endif endif
@ -126,38 +126,29 @@ function! s:Opener._isWindowUsable(winnumber)
endfunction endfunction
" FUNCTION: Opener.New(path, opts) {{{1 " FUNCTION: Opener.New(path, opts) {{{1
" Instantiate a new NERDTreeOpener object.
" Args: " Args:
" " a:path: the path object that is to be opened
" a:path: The path object that is to be opened. " a:opts: a dictionary containing the following optional keys...
" " 'where': specifies whether the node should be opened in new split, in
" a:opts: " a new tab or, in the last window; takes values "v", "h", or "t"
" " 'reuse': if file is already shown in a window, jump there; takes values
" A dictionary containing the following keys (all optional): " "all", "currenttab", or empty
" 'where': Specifies whether the node should be opened in new split/tab or in " 'keepopen': boolean (0 or 1); if true, the tree window will not be closed
" the previous window. Can be either 'v' or 'h' or 't' (for open in " 'stay': boolean (0 or 1); if true, remain in tree window after opening
" new tab)
" 'reuse': if a window is displaying the file then jump the cursor there. Can
" 'all', 'currenttab' or empty to not reuse.
" 'keepopen': dont close the tree window
" 'stay': open the file, but keep the cursor in the tree win
function! s:Opener.New(path, opts) function! s:Opener.New(path, opts)
let newObj = copy(self) let l:newOpener = copy(self)
let newObj._path = a:path let l:newOpener._keepopen = nerdtree#has_opt(a:opts, 'keepopen')
let newObj._stay = nerdtree#has_opt(a:opts, 'stay') let l:newOpener._nerdtree = b:NERDTree
let l:newOpener._path = a:path
let l:newOpener._reuse = has_key(a:opts, 'reuse') ? a:opts['reuse'] : ''
let l:newOpener._stay = nerdtree#has_opt(a:opts, 'stay')
let l:newOpener._where = has_key(a:opts, 'where') ? a:opts['where'] : ''
if has_key(a:opts, 'reuse') call l:newOpener._saveCursorPos()
let newObj._reuse = a:opts['reuse']
else
let newObj._reuse = ''
endif
let newObj._keepopen = nerdtree#has_opt(a:opts, 'keepopen') return l:newOpener
let newObj._where = has_key(a:opts, 'where') ? a:opts['where'] : ''
let newObj._nerdtree = b:NERDTree
call newObj._saveCursorPos()
return newObj
endfunction endfunction
" FUNCTION: Opener._newSplit() {{{1 " FUNCTION: Opener._newSplit() {{{1
@ -242,33 +233,40 @@ endfunction
" FUNCTION: Opener.open(target) {{{1 " FUNCTION: Opener.open(target) {{{1
function! s:Opener.open(target) function! s:Opener.open(target)
if self._path.isDirectory if self._path.isDirectory
call self._openDirectory(a:target) call self._openDirectory(a:target)
else return
call self._openFile()
endif endif
call self._openFile()
endfunction endfunction
" FUNCTION: Opener._openFile() {{{1 " FUNCTION: Opener._openFile() {{{1
function! s:Opener._openFile() function! s:Opener._openFile()
if self._reuseWindow() if self._reuseWindow()
return return
endif endif
call self._gotoTargetWin() call self._gotoTargetWin()
call self._path.edit()
if self._stay if self._stay
silent call self._path.edit()
call self._restoreCursorPos() call self._restoreCursorPos()
return
endif endif
call self._path.edit()
endfunction endfunction
" FUNCTION: Opener._openDirectory(node) {{{1 " FUNCTION: Opener._openDirectory(node) {{{1
function! s:Opener._openDirectory(node) function! s:Opener._openDirectory(node)
if self._nerdtree.isWinTree()
call self._gotoTargetWin() call self._gotoTargetWin()
if self._nerdtree.isWinTree()
call g:NERDTreeCreator.CreateWindowTree(a:node.path.str()) call g:NERDTreeCreator.CreateWindowTree(a:node.path.str())
else else
call self._gotoTargetWin()
if empty(self._where) if empty(self._where)
call b:NERDTree.changeRoot(a:node) call b:NERDTree.changeRoot(a:node)
elseif self._where == 't' elseif self._where == 't'

View File

@ -21,12 +21,19 @@ function! s:TreeDirNode.AbsoluteTreeRoot()
endfunction endfunction
" FUNCTION: TreeDirNode.activate([options]) {{{1 " FUNCTION: TreeDirNode.activate([options]) {{{1
unlet s:TreeDirNode.activate
function! s:TreeDirNode.activate(...) function! s:TreeDirNode.activate(...)
let opts = a:0 ? a:1 : {} let l:options = (a:0 > 0) ? a:1 : {}
call self.toggleOpen(opts)
call self.toggleOpen(l:options)
" Note that we only re-render the NERDTree for this node if we did NOT
" create a new node and render it in a new window or tab. In the latter
" case, rendering the NERDTree for this node could overwrite the text of
" the new NERDTree!
if !has_key(l:options, 'where') || empty(l:options['where'])
call self.getNerdtree().render() call self.getNerdtree().render()
call self.putCursorHere(0, 0) call self.putCursorHere(0, 0)
endif
endfunction endfunction
" FUNCTION: TreeDirNode.addChild(treenode, inOrder) {{{1 " FUNCTION: TreeDirNode.addChild(treenode, inOrder) {{{1

View File

@ -47,6 +47,8 @@ function! s:UI._dumpHelp()
let help .= "\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n" let help .= "\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n"
let help .= "\" ". g:NERDTreeMapActivateNode .": open & close node\n" let help .= "\" ". g:NERDTreeMapActivateNode .": open & close node\n"
let help .= "\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n" let help .= "\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n"
let help .= "\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
let help .= "\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
let help .= "\" ". g:NERDTreeMapCloseDir .": close parent of node\n" let help .= "\" ". g:NERDTreeMapCloseDir .": close parent of node\n"
let help .= "\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n" let help .= "\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n"
let help .= "\" current node recursively\n" let help .= "\" current node recursively\n"