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,11 +1,17 @@
"CLASS: Creator " ============================================================================
"Creates tab/window/mirror nerdtree windows. Sets up all the window and " CLASS: Creator
"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
"FUNCTION: s:Creator._bindMappings() {{{1 " FUNCTION: s:Creator._bindMappings() {{{1
function! s:Creator._bindMappings() function! s:Creator._bindMappings()
"make <cr> do the same as the activate node mapping "make <cr> do the same as the activate node mapping
nnoremap <silent> <buffer> <cr> :call nerdtree#ui_glue#invokeKeyMap(g:NERDTreeMapActivateNode)<cr> nnoremap <silent> <buffer> <cr> :call nerdtree#ui_glue#invokeKeyMap(g:NERDTreeMapActivateNode)<cr>
@ -22,7 +28,7 @@ function! s:Creator._bindMappings()
command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write() command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write()
endfunction endfunction
"FUNCTION: s:Creator._broadcastInitEvent() {{{1 " FUNCTION: s:Creator._broadcastInitEvent() {{{1
function! s:Creator._broadcastInitEvent() function! s:Creator._broadcastInitEvent()
silent doautocmd User NERDTreeInit silent doautocmd User NERDTreeInit
endfunction endfunction
@ -32,55 +38,48 @@ function! s:Creator.BufNamePrefix()
return 'NERD_tree_' return 'NERD_tree_'
endfunction endfunction
"FUNCTION: s:Creator.CreateTabTree(a:name) {{{1 " FUNCTION: s:Creator.CreateTabTree(a:name) {{{1
function! s:Creator.CreateTabTree(name) function! s:Creator.CreateTabTree(name)
let creator = s:Creator.New() let creator = s:Creator.New()
call creator.createTabTree(a:name) call creator.createTabTree(a:name)
endfunction 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)
call self._broadcastInitEvent() call self._broadcastInitEvent()
endfunction endfunction
"FUNCTION: s:Creator.CreateWindowTree(dir) {{{1 " FUNCTION: s:Creator.CreateWindowTree(dir) {{{1
function! s:Creator.CreateWindowTree(dir) function! s:Creator.CreateWindowTree(dir)
let creator = s:Creator.New() let creator = s:Creator.New()
call creator.createWindowTree(a:dir) call creator.createWindowTree(a:dir)
endfunction endfunction
"FUNCTION: s:Creator.createWindowTree(dir) {{{1 " FUNCTION: s:Creator.createWindowTree(dir) {{{1
function! s:Creator.createWindowTree(dir) function! s:Creator.createWindowTree(dir)
try try
let path = g:NERDTreePath.New(a:dir) let path = g:NERDTreePath.New(a:dir)
@ -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
@ -177,9 +171,9 @@ function! s:Creator.createMirror()
endif endif
endfunction endfunction
"FUNCTION: s:Creator._createTreeWin() {{{1 " FUNCTION: s:Creator._createTreeWin() {{{1
"Inits the NERD tree window. ie. opens it, sizes it, sets all the local " Inits the NERD tree window. ie. opens it, sizes it, sets all the local
"options etc " options etc
function! s:Creator._createTreeWin() function! s:Creator._createTreeWin()
"create the nerd tree window "create the nerd tree window
let splitLocation = g:NERDTreeWinPos ==# "left" ? "topleft " : "botright " let splitLocation = g:NERDTreeWinPos ==# "left" ? "topleft " : "botright "
@ -198,7 +192,7 @@ function! s:Creator._createTreeWin()
call self._setCommonBufOptions() call self._setCommonBufOptions()
endfunction endfunction
"FUNCTION: s:Creator._isBufHidden(nr) {{{1 " FUNCTION: s:Creator._isBufHidden(nr) {{{1
function! s:Creator._isBufHidden(nr) function! s:Creator._isBufHidden(nr)
redir => bufs redir => bufs
silent ls! silent ls!
@ -207,7 +201,7 @@ function! s:Creator._isBufHidden(nr)
return bufs =~ a:nr . '..h' return bufs =~ a:nr . '..h'
endfunction endfunction
"FUNCTION: s:Creator.New() {{{1 " FUNCTION: s:Creator.New() {{{1
function! s:Creator.New() function! s:Creator.New()
let newCreator = copy(self) let newCreator = copy(self)
return newCreator return newCreator
@ -232,8 +226,8 @@ function! s:Creator._nextBufferNumber()
return s:Creator._NextBufNum return s:Creator._NextBufNum
endfunction endfunction
"FUNCTION: s:Creator._pathForString(str) {{{1 " FUNCTION: s:Creator._pathForString(str) {{{1
"find a bookmark or adirectory for the given string " find a bookmark or adirectory for the given string
function! s:Creator._pathForString(str) function! s:Creator._pathForString(str)
let path = {} let path = {}
if g:NERDTreeBookmark.BookmarkExistsFor(a:str) if g:NERDTreeBookmark.BookmarkExistsFor(a:str)
@ -278,7 +272,7 @@ function! s:Creator._removeTreeBufForTab()
unlet t:NERDTreeBufName unlet t:NERDTreeBufName
endfunction endfunction
"FUNCTION: s:Creator._setCommonBufOptions() {{{1 " FUNCTION: s:Creator._setCommonBufOptions() {{{1
function! s:Creator._setCommonBufOptions() function! s:Creator._setCommonBufOptions()
"throwaway buffer options "throwaway buffer options
setlocal noswapfile setlocal noswapfile
@ -310,7 +304,7 @@ function! s:Creator._setCommonBufOptions()
setlocal filetype=nerdtree setlocal filetype=nerdtree
endfunction endfunction
"FUNCTION: s:Creator._setupStatusline() {{{1 " FUNCTION: s:Creator._setupStatusline() {{{1
function! s:Creator._setupStatusline() function! s:Creator._setupStatusline()
if g:NERDTreeStatusline != -1 if g:NERDTreeStatusline != -1
let &l:statusline = g:NERDTreeStatusline let &l:statusline = g:NERDTreeStatusline
@ -335,19 +329,19 @@ function! s:Creator._tabpagevar(tabnr, var)
return v return v
endfunction endfunction
"FUNCTION: s:Creator.ToggleTabTree(dir) {{{1 " FUNCTION: s:Creator.ToggleTabTree(dir) {{{1
function! s:Creator.ToggleTabTree(dir) function! s:Creator.ToggleTabTree(dir)
let creator = s:Creator.New() let creator = s:Creator.New()
call creator.toggleTabTree(a:dir) call creator.toggleTabTree(a:dir)
endfunction endfunction
"FUNCTION: s:Creator.toggleTabTree(dir) {{{1 " FUNCTION: s:Creator.toggleTabTree(dir) {{{1
"Toggles the NERD tree. I.e the NERD tree is open, it is closed, if it is " Toggles the NERD tree. I.e the NERD tree is open, it is closed, if it is
"closed it is restored or initialized (if it doesnt exist) " closed it is restored or initialized (if it doesnt exist)
" "
"Args: " Args:
"dir: the full path for the root node (is only used if the NERD tree is being " dir: the full path for the root node (is only used if the NERD tree is being
"initialized. " initialized.
function! s:Creator.toggleTabTree(dir) function! s:Creator.toggleTabTree(dir)
if g:NERDTree.ExistsForTab() if g:NERDTree.ExistsForTab()
if !g:NERDTree.IsOpen() if !g:NERDTree.IsOpen()

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)
call self._gotoTargetWin()
if self._nerdtree.isWinTree() if self._nerdtree.isWinTree()
call self._gotoTargetWin()
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.getNerdtree().render() call self.toggleOpen(l:options)
call self.putCursorHere(0, 0)
" 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.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"