Merge commit 'f343f5dd0d0364d42982469888bec6dc7a02c9dd' into main
commit
7fcaef99ad
@ -0,0 +1,145 @@
|
||||
5.0.0
|
||||
- Refactor the code significantly:
|
||||
* Break the classes out into their own files.
|
||||
* Make the majority of the code OO - previously large parts were
|
||||
effectively a tangle of "global" methods.
|
||||
- Add an API to assign flags to nodes. This allows VCS plugins like
|
||||
https://github.com/Xuyuanp/nerdtree-git-plugin to exist. Thanks to
|
||||
Xuyuanp for helping design/test/build said API.
|
||||
- add 'scope' argument to the key map API see :help NERDTreeAddKeyMap()
|
||||
- add magic [[dir]] and [[file]] flags to NERDTreeIgnore
|
||||
- add support for custom path filters. See :help NERDTreeAddPathFilter()
|
||||
- add path listener API. See :help NERDTreePathListenerAPI.
|
||||
- expand the fs menu functionality to list file properties (PhilRunninger,
|
||||
apbarrero, JESii)
|
||||
- make bookmarks work with `~` home shortcuts (hiberabyss)
|
||||
- show OSX specific fsmenu options in regular vim on mac (evindor)
|
||||
- make dir arrow icons configurable (PickRelated)
|
||||
- optimise node sorting performance when opening large dirs (vtsang)
|
||||
- make the root note render prettier by truncating it at a path slash (gcmt)
|
||||
- remove NERDChristmasTree option - its always christmas now
|
||||
- add "cascade" open and closing for dirs containing only another single
|
||||
dir. See :help NERDTreeCascadeOpenSingleChildDir (pendulm)
|
||||
|
||||
Many other fixes, doc updates and contributions from:
|
||||
actionshrimp
|
||||
SchDen
|
||||
egalpin
|
||||
cperl82 - many small fixes
|
||||
toiffel
|
||||
WoLpH
|
||||
handcraftedbits
|
||||
devmanhinton
|
||||
xiaodili
|
||||
zhangoose
|
||||
gastropoda
|
||||
mixvin
|
||||
alvan
|
||||
lucascaton
|
||||
kelaban
|
||||
shanesmith
|
||||
staeff
|
||||
pendulm
|
||||
stephenprater
|
||||
franksort
|
||||
agrussellknives
|
||||
AndrewRadev
|
||||
Twinside
|
||||
|
||||
4.2.0
|
||||
- Add NERDTreeDirArrows option to make the UI use pretty arrow chars
|
||||
instead of the old +~| chars to define the tree structure (sickill)
|
||||
- shift the syntax highlighting out into its own syntax file (gnap)
|
||||
- add some mac specific options to the filesystem menu - for macvim
|
||||
only (andersonfreitas)
|
||||
- Add NERDTreeMinimalUI option to remove some non functional parts of the
|
||||
nerdtree ui (camthompson)
|
||||
- tweak the behaviour of :NERDTreeFind - see :help :NERDTreeFind for the
|
||||
new behaviour (benjamingeiger)
|
||||
- if no name is given to :Bookmark, make it default to the name of the
|
||||
target file/dir (minyoung)
|
||||
- use 'file' completion when doing copying, create, and move
|
||||
operations (EvanDotPro)
|
||||
- lots of misc bug fixes (paddyoloughlin, sdewald, camthompson, Vitaly
|
||||
Bogdanov, AndrewRadev, mathias, scottstvnsn, kml, wycats, me RAWR!)
|
||||
|
||||
4.1.0
|
||||
features:
|
||||
- NERDTreeFind to reveal the node for the current buffer in the tree,
|
||||
see |NERDTreeFind|. This effectively merges the FindInNERDTree plugin (by
|
||||
Doug McInnes) into the script.
|
||||
- make NERDTreeQuitOnOpen apply to the t/T keymaps too. Thanks to Stefan
|
||||
Ritter and Rémi Prévost.
|
||||
- truncate the root node if wider than the tree window. Thanks to Victor
|
||||
Gonzalez.
|
||||
|
||||
bugfixes:
|
||||
- really fix window state restoring
|
||||
- fix some win32 path escaping issues. Thanks to Stephan Baumeister, Ricky,
|
||||
jfilip1024, and Chris Chambers
|
||||
|
||||
4.0.0
|
||||
- add a new programmable menu system (see :help NERDTreeMenu).
|
||||
- add new APIs to add menus/menu-items to the menu system as well as
|
||||
custom key mappings to the NERD tree buffer (see :help NERDTreeAPI).
|
||||
- removed the old API functions
|
||||
- added a mapping to maximize/restore the size of nerd tree window, thanks
|
||||
to Guillaume Duranceau for the patch. See :help NERDTree-A for details.
|
||||
|
||||
- fix a bug where secondary nerd trees (netrw hijacked trees) and
|
||||
NERDTreeQuitOnOpen didnt play nicely, thanks to Curtis Harvey.
|
||||
- fix a bug where the script ignored directories whose name ended in a dot,
|
||||
thanks to Aggelos Orfanakos for the patch.
|
||||
- fix a bug when using the x mapping on the tree root, thanks to Bryan
|
||||
Venteicher for the patch.
|
||||
- fix a bug where the cursor position/window size of the nerd tree buffer
|
||||
wasnt being stored on closing the window, thanks to Richard Hart.
|
||||
- fix a bug where NERDTreeMirror would mirror the wrong tree
|
||||
|
||||
3.1.1
|
||||
- fix a bug where a non-listed no-name buffer was getting created every
|
||||
time the tree windows was created, thanks to Derek Wyatt and owen1
|
||||
- make <CR> behave the same as the 'o' mapping
|
||||
- some helptag fixes in the doc, thanks strull
|
||||
- fix a bug when using :set nohidden and opening a file where the previous
|
||||
buf was modified. Thanks iElectric
|
||||
- other minor fixes
|
||||
|
||||
3.1.0
|
||||
New features:
|
||||
- add mappings to open files in a vsplit, see :help NERDTree-s and :help
|
||||
NERDTree-gs
|
||||
- make the statusline for the nerd tree window default to something
|
||||
hopefully more useful. See :help 'NERDTreeStatusline'
|
||||
Bugfixes:
|
||||
- make the hijack netrw functionality work when vim is started with "vim
|
||||
<some dir>" (thanks to Alf Mikula for the patch).
|
||||
- fix a bug where the CWD wasnt being changed for some operations even when
|
||||
NERDTreeChDirMode==2 (thanks to Lucas S. Buchala)
|
||||
- add -bar to all the nerd tree :commands so they can chain with other
|
||||
:commands (thanks to tpope)
|
||||
- fix bugs when ignorecase was set (thanks to nach)
|
||||
- fix a bug with the relative path code (thanks to nach)
|
||||
- fix a bug where doing a :cd would cause :NERDTreeToggle to fail (thanks nach)
|
||||
|
||||
|
||||
3.0.1
|
||||
Bugfixes:
|
||||
- fix bugs with :NERDTreeToggle and :NERDTreeMirror when 'hidden
|
||||
was not set
|
||||
- fix a bug where :NERDTree <path> would fail if <path> was relative and
|
||||
didnt start with a ./ or ../ Thanks to James Kanze.
|
||||
- make the q mapping work with secondary (:e <dir> style) trees,
|
||||
thanks to jamessan
|
||||
- fix a bunch of small bugs with secondary trees
|
||||
|
||||
More insane refactoring.
|
||||
|
||||
3.0.0
|
||||
- hijack netrw so that doing an :edit <directory> will put a NERD tree in
|
||||
the window rather than a netrw browser. See :help 'NERDTreeHijackNetrw'
|
||||
- allow sharing of trees across tabs, see :help :NERDTreeMirror
|
||||
- remove "top" and "bottom" as valid settings for NERDTreeWinPos
|
||||
- change the '<tab>' mapping to 'i'
|
||||
- change the 'H' mapping to 'I'
|
||||
- lots of refactoring
|
@ -0,0 +1,13 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,644 @@
|
||||
if exists("g:loaded_nerdtree_ui_glue_autoload")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_nerdtree_ui_glue_autoload = 1
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#createDefaultBindings() {{{1
|
||||
function! nerdtree#ui_glue#createDefaultBindings()
|
||||
let s = '<SNR>' . s:SID() . '_'
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': '<MiddleRelease>', 'scope': "all", 'callback': s."handleMiddleMouse" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<LeftRelease>', 'scope': "all", 'callback': s."handleLeftClick" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "DirNode", 'callback': s."activateDirNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."activateFileNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "Bookmark", 'callback': s."activateBookmark" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "all", 'callback': s."activateAll" })
|
||||
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "DirNode", 'callback': s."activateDirNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "FileNode", 'callback': s."activateFileNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "Bookmark", 'callback': s."activateBookmark" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "all", 'callback': s."activateAll" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': "Node", 'callback': s."openHSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': "Node", 'callback': s."openVSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': "Bookmark", 'callback': s."openHSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': "Bookmark", 'callback': s."openVSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': "Node", 'callback': s."previewNodeCurrent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': "Node", 'callback': s."previewNodeVSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': "Node", 'callback': s."previewNodeHSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': "Bookmark", 'callback': s."previewNodeCurrent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': "Bookmark", 'callback': s."previewNodeVSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': "Bookmark", 'callback': s."previewNodeHSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenRecursively, 'scope': "DirNode", 'callback': s."openNodeRecursively" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapUpdir, 'scope': "all", 'callback': s."upDirCurrentRootClosed" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapUpdirKeepOpen, 'scope': "all", 'callback': s."upDirCurrentRootOpen" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapChangeRoot, 'scope': "Node", 'callback': s."chRoot" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapChdir, 'scope': "Node", 'callback': s."chCwd" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapQuit, 'scope': "all", 'callback': s."closeTreeWindow" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCWD, 'scope': "all", 'callback': "nerdtree#ui_glue#chRootCwd" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefreshRoot, 'scope': "all", 'callback': s."refreshRoot" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefresh, 'scope': "Node", 'callback': s."refreshCurrent" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapHelp, 'scope': "all", 'callback': s."displayHelp" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleZoom, 'scope': "all", 'callback': s."toggleZoom" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleHidden, 'scope': "all", 'callback': s."toggleShowHidden" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFilters, 'scope': "all", 'callback': s."toggleIgnoreFilter" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFiles, 'scope': "all", 'callback': s."toggleShowFiles" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleBookmarks, 'scope': "all", 'callback': s."toggleShowBookmarks" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseDir, 'scope': "Node", 'callback': s."closeCurrentDir" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseChildren, 'scope': "DirNode", 'callback': s."closeChildren" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapMenu, 'scope': "Node", 'callback': s."showMenu" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpParent, 'scope': "Node", 'callback': s."jumpToParent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpFirstChild, 'scope': "Node", 'callback': s."jumpToFirstChild" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpLastChild, 'scope': "Node", 'callback': s."jumpToLastChild" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpRoot, 'scope': "all", 'callback': s."jumpToRoot" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': "Node", 'callback': s."jumpToNextSibling" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': "Node", 'callback': s."jumpToPrevSibling" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Node", 'callback': s."openInNewTab" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Node", 'callback': s."openInNewTabSilent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Bookmark", 'callback': s."openInNewTab" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Bookmark", 'callback': s."openInNewTabSilent" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenExpl, 'scope': "DirNode", 'callback': s."openExplorer" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapDeleteBookmark, 'scope': "Bookmark", 'callback': s."deleteBookmark" })
|
||||
endfunction
|
||||
|
||||
|
||||
"SECTION: Interface bindings {{{1
|
||||
"============================================================
|
||||
|
||||
"FUNCTION: s:activateAll() {{{1
|
||||
"handle the user activating the updir line
|
||||
function! s:activateAll()
|
||||
if getline(".") ==# g:NERDTreeUI.UpDirLine()
|
||||
return nerdtree#ui_glue#upDir(0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateDirNode() {{{1
|
||||
"handle the user activating a tree node
|
||||
function! s:activateDirNode(node)
|
||||
call a:node.activate()
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateFileNode() {{{1
|
||||
"handle the user activating a tree node
|
||||
function! s:activateFileNode(node)
|
||||
call a:node.activate({'reuse': 'all', 'where': 'p'})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateBookmark() {{{1
|
||||
"handle the user activating a bookmark
|
||||
function! s:activateBookmark(bm)
|
||||
call a:bm.activate(!a:bm.path.isDirectory ? {'where': 'p'} : {})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#bookmarkNode(name) {{{1
|
||||
" Associate the current node with the given name
|
||||
function! nerdtree#ui_glue#bookmarkNode(...)
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
let name = a:1
|
||||
if empty(name)
|
||||
let name = currentNode.path.getLastPathComponent(0)
|
||||
endif
|
||||
try
|
||||
call currentNode.bookmark(name)
|
||||
call b:NERDTree.render()
|
||||
catch /^NERDTree.IllegalBookmarkNameError/
|
||||
call nerdtree#echo("bookmark names must not contain spaces")
|
||||
endtry
|
||||
else
|
||||
call nerdtree#echo("select a node first")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chCwd(node) {{{1
|
||||
function! s:chCwd(node)
|
||||
try
|
||||
call a:node.path.changeToDir()
|
||||
catch /^NERDTree.PathChangeError/
|
||||
call nerdtree#echoWarning("could not change cwd")
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chRoot(node) {{{1
|
||||
" changes the current root to the selected one
|
||||
function! s:chRoot(node)
|
||||
call a:node.makeRoot()
|
||||
call b:NERDTree.render()
|
||||
call b:NERDTreeRoot.putCursorHere(0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1
|
||||
" changes the current root to CWD
|
||||
function! nerdtree#ui_glue#chRootCwd()
|
||||
try
|
||||
let cwd = g:NERDTreePath.New(getcwd())
|
||||
catch /^NERDTree.InvalidArgumentsError/
|
||||
call nerdtree#echo("current directory does not exist.")
|
||||
return
|
||||
endtry
|
||||
if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str()
|
||||
return
|
||||
endif
|
||||
call s:chRoot(g:NERDTreeDirNode.New(cwd))
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1
|
||||
function! nerdtree#ui_glue#clearBookmarks(bookmarks)
|
||||
if a:bookmarks ==# ''
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
call currentNode.clearBookmarks()
|
||||
endif
|
||||
else
|
||||
for name in split(a:bookmarks, ' ')
|
||||
let bookmark = g:NERDTreeBookmark.BookmarkFor(name)
|
||||
call bookmark.delete()
|
||||
endfor
|
||||
endif
|
||||
call b:NERDTree.render()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeChildren(node) {{{1
|
||||
" closes all childnodes of the current node
|
||||
function! s:closeChildren(node)
|
||||
call a:node.closeChildren()
|
||||
call b:NERDTree.render()
|
||||
call a:node.putCursorHere(0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeCurrentDir(node) {{{1
|
||||
" closes the parent dir of the current node
|
||||
function! s:closeCurrentDir(node)
|
||||
let parent = a:node.parent
|
||||
if parent ==# {} || parent.isRoot()
|
||||
call nerdtree#echo("cannot close tree root")
|
||||
else
|
||||
while g:NERDTreeCascadeOpenSingleChildDir && !parent.parent.isRoot()
|
||||
if parent.parent.getVisibleChildCount() == 1
|
||||
call parent.close()
|
||||
let parent = parent.parent
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
call parent.close()
|
||||
call b:NERDTree.render()
|
||||
call parent.putCursorHere(0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeTreeWindow() {{{1
|
||||
" close the tree window
|
||||
function! s:closeTreeWindow()
|
||||
if b:NERDTreeType ==# "secondary" && b:NERDTreePreviousBuf != -1
|
||||
exec "buffer " . b:NERDTreePreviousBuf
|
||||
else
|
||||
if winnr("$") > 1
|
||||
call g:NERDTree.Close()
|
||||
else
|
||||
call nerdtree#echo("Cannot close last window")
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:deleteBookmark(bm) {{{1
|
||||
" if the cursor is on a bookmark, prompt to delete
|
||||
function! s:deleteBookmark(bm)
|
||||
echo "Are you sure you wish to delete the bookmark:\n\"" . a:bm.name . "\" (yN):"
|
||||
|
||||
if nr2char(getchar()) ==# 'y'
|
||||
try
|
||||
call a:bm.delete()
|
||||
call b:NERDTree.render()
|
||||
redraw
|
||||
catch /^NERDTree/
|
||||
call nerdtree#echoWarning("Could not remove bookmark")
|
||||
endtry
|
||||
else
|
||||
call nerdtree#echo("delete aborted" )
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:displayHelp() {{{1
|
||||
" toggles the help display
|
||||
function! s:displayHelp()
|
||||
let b:treeShowHelp = b:treeShowHelp ? 0 : 1
|
||||
call b:NERDTree.render()
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:findAndRevealPath() {{{1
|
||||
function! s:findAndRevealPath()
|
||||
try
|
||||
let p = g:NERDTreePath.New(expand("%:p"))
|
||||
catch /^NERDTree.InvalidArgumentsError/
|
||||
call nerdtree#echo("no file for the current buffer")
|
||||
return
|
||||
endtry
|
||||
|
||||
if p.isUnixHiddenPath()
|
||||
let showhidden=g:NERDTreeShowHidden
|
||||
let g:NERDTreeShowHidden = 1
|
||||
endif
|
||||
|
||||
if !g:NERDTree.ExistsForTab()
|
||||
try
|
||||
let cwd = g:NERDTreePath.New(getcwd())
|
||||
catch /^NERDTree.InvalidArgumentsError/
|
||||
call nerdtree#echo("current directory does not exist.")
|
||||
let cwd = p.getParent()
|
||||
endtry
|
||||
|
||||
if p.isUnder(cwd)
|
||||
call g:NERDTreeCreator.CreatePrimary(cwd.str())
|
||||
else
|
||||
call g:NERDTreeCreator.CreatePrimary(p.getParent().str())
|
||||
endif
|
||||
else
|
||||
if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
|
||||
if !g:NERDTree.IsOpen()
|
||||
call g:NERDTreeCreator.TogglePrimary('')
|
||||
else
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
endif
|
||||
let b:NERDTreeShowHidden = g:NERDTreeShowHidden
|
||||
call s:chRoot(g:NERDTreeDirNode.New(p.getParent()))
|
||||
else
|
||||
if !g:NERDTree.IsOpen()
|
||||
call g:NERDTreeCreator.TogglePrimary("")
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
call b:NERDTreeRoot.reveal(p)
|
||||
|
||||
if p.isUnixHiddenFile()
|
||||
let g:NERDTreeShowHidden = showhidden
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:handleLeftClick() {{{1
|
||||
"Checks if the click should open the current node
|
||||
function! s:handleLeftClick()
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
|
||||
"the dir arrows are multibyte chars, and vim's string functions only
|
||||
"deal with single bytes - so split the line up with the hack below and
|
||||
"take the line substring manually
|
||||
let line = split(getline(line(".")), '\zs')
|
||||
let startToCur = ""
|
||||
for i in range(0,len(line)-1)
|
||||
let startToCur .= line[i]
|
||||
endfor
|
||||
|
||||
if currentNode.path.isDirectory
|
||||
if startToCur =~# g:NERDTreeUI.MarkupReg() && startToCur =~# '[+~'.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.'] \?$'
|
||||
call currentNode.activate()
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3
|
||||
let char = strpart(startToCur, strlen(startToCur)-1, 1)
|
||||
if char !~# g:NERDTreeUI.MarkupReg()
|
||||
if currentNode.path.isDirectory
|
||||
call currentNode.activate()
|
||||
else
|
||||
call currentNode.activate({'reuse': 'all', 'where': 'p'})
|
||||
endif
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:handleMiddleMouse() {{{1
|
||||
function! s:handleMiddleMouse()
|
||||
let curNode = g:NERDTreeFileNode.GetSelected()
|
||||
if curNode ==# {}
|
||||
call nerdtree#echo("Put the cursor on a node first" )
|
||||
return
|
||||
endif
|
||||
|
||||
if curNode.path.isDirectory
|
||||
call nerdtree#openExplorer(curNode)
|
||||
else
|
||||
call curNode.open({'where': 'h'})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToChild(direction) {{{2
|
||||
" Args:
|
||||
" direction: 0 if going to first child, 1 if going to last
|
||||
function! s:jumpToChild(currentNode, direction)
|
||||
if a:currentNode.isRoot()
|
||||
return nerdtree#echo("cannot jump to " . (a:direction ? "last" : "first") . " child")
|
||||
end
|
||||
let dirNode = a:currentNode.parent
|
||||
let childNodes = dirNode.getVisibleChildren()
|
||||
|
||||
let targetNode = childNodes[0]
|
||||
if a:direction
|
||||
let targetNode = childNodes[len(childNodes) - 1]
|
||||
endif
|
||||
|
||||
if targetNode.equals(a:currentNode)
|
||||
let siblingDir = a:currentNode.parent.findOpenDirSiblingWithVisibleChildren(a:direction)
|
||||
if siblingDir != {}
|
||||
let indx = a:direction ? siblingDir.getVisibleChildCount()-1 : 0
|
||||
let targetNode = siblingDir.getChildByIndex(indx, 1)
|
||||
endif
|
||||
endif
|
||||
|
||||
call targetNode.putCursorHere(1, 0)
|
||||
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#invokeKeyMap(key) {{{1
|
||||
"this is needed since I cant figure out how to invoke dict functions from a
|
||||
"key map
|
||||
function! nerdtree#ui_glue#invokeKeyMap(key)
|
||||
call g:NERDTreeKeyMap.Invoke(a:key)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToFirstChild() {{{1
|
||||
" wrapper for the jump to child method
|
||||
function! s:jumpToFirstChild(node)
|
||||
call s:jumpToChild(a:node, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToLastChild() {{{1
|
||||
" wrapper for the jump to child method
|
||||
function! s:jumpToLastChild(node)
|
||||
call s:jumpToChild(a:node, 1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToParent(node) {{{1
|
||||
" moves the cursor to the parent of the current node
|
||||
function! s:jumpToParent(node)
|
||||
if !empty(a:node.parent)
|
||||
call a:node.parent.putCursorHere(1, 0)
|
||||
call b:NERDTree.ui.centerView()
|
||||
else
|
||||
call nerdtree#echo("cannot jump to parent")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToRoot() {{{1
|
||||
" moves the cursor to the root node
|
||||
function! s:jumpToRoot()
|
||||
call b:NERDTreeRoot.putCursorHere(1, 0)
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToNextSibling(node) {{{1
|
||||
function! s:jumpToNextSibling(node)
|
||||
call s:jumpToSibling(a:node, 1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToPrevSibling(node) {{{1
|
||||
function! s:jumpToPrevSibling(node)
|
||||
call s:jumpToSibling(a:node, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToSibling(currentNode, forward) {{{2
|
||||
" moves the cursor to the sibling of the current node in the given direction
|
||||
"
|
||||
" Args:
|
||||
" forward: 1 if the cursor should move to the next sibling, 0 if it should
|
||||
" move back to the previous sibling
|
||||
function! s:jumpToSibling(currentNode, forward)
|
||||
let sibling = a:currentNode.findSibling(a:forward)
|
||||
|
||||
if !empty(sibling)
|
||||
call sibling.putCursorHere(1, 0)
|
||||
call b:NERDTree.ui.centerView()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#openBookmark(name) {{{1
|
||||
" put the cursor on the given bookmark and, if its a file, open it
|
||||
function! nerdtree#ui_glue#openBookmark(name)
|
||||
try
|
||||
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0)
|
||||
call targetNode.putCursorHere(0, 1)
|
||||
redraw!
|
||||
catch /^NERDTree.BookmarkedNodeNotFoundError/
|
||||
call nerdtree#echo("note - target node is not cached")
|
||||
let bookmark = g:NERDTreeBookmark.BookmarkFor(a:name)
|
||||
let targetNode = g:NERDTreeFileNode.New(bookmark.path)
|
||||
endtry
|
||||
if targetNode.path.isDirectory
|
||||
call targetNode.openExplorer()
|
||||
else
|
||||
call targetNode.open({'where': 'p'})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openHSplit(target) {{{1
|
||||
function! s:openHSplit(target)
|
||||
call a:target.activate({'where': 'h'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openVSplit(target) {{{1
|
||||
function! s:openVSplit(target)
|
||||
call a:target.activate({'where': 'v'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openExplorer(node) {{{1
|
||||
function! s:openExplorer(node)
|
||||
call a:node.openExplorer()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openInNewTab(target) {{{1
|
||||
function! s:openInNewTab(target)
|
||||
call a:target.activate({'where': 't'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openInNewTabSilent(target) {{{1
|
||||
function! s:openInNewTabSilent(target)
|
||||
call a:target.activate({'where': 't', 'stay': 1})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openNodeRecursively(node) {{{1
|
||||
function! s:openNodeRecursively(node)
|
||||
call nerdtree#echo("Recursively opening node. Please wait...")
|
||||
call a:node.openRecursively()
|
||||
call b:NERDTree.render()
|
||||
redraw
|
||||
call nerdtree#echo("Recursively opening node. Please wait... DONE")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeCurrent(node) {{{1
|
||||
function! s:previewNodeCurrent(node)
|
||||
call a:node.open({'stay': 1, 'where': 'p', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeHSplit(node) {{{1
|
||||
function! s:previewNodeHSplit(node)
|
||||
call a:node.open({'stay': 1, 'where': 'h', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeVSplit(node) {{{1
|
||||
function! s:previewNodeVSplit(node)
|
||||
call a:node.open({'stay': 1, 'where': 'v', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#revealBookmark(name) {{{1
|
||||
" put the cursor on the node associate with the given name
|
||||
function! nerdtree#ui_glue#revealBookmark(name)
|
||||
try
|
||||
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0)
|
||||
call targetNode.putCursorHere(0, 1)
|
||||
catch /^NERDTree.BookmarkNotFoundError/
|
||||
call nerdtree#echo("Bookmark isnt cached under the current root")
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:refreshRoot() {{{1
|
||||
" Reloads the current root. All nodes below this will be lost and the root dir
|
||||
" will be reloaded.
|
||||
function! s:refreshRoot()
|
||||
call nerdtree#echo("Refreshing the root node. This could take a while...")
|
||||
call b:NERDTreeRoot.refresh()
|
||||
call b:NERDTree.render()
|
||||
redraw
|
||||
call nerdtree#echo("Refreshing the root node. This could take a while... DONE")
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:refreshCurrent(node) {{{1
|
||||
" refreshes the root for the current node
|
||||
function! s:refreshCurrent(node)
|
||||
let node = a:node
|
||||
if !node.path.isDirectory
|
||||
let node = node.parent
|
||||
endif
|
||||
|
||||
call nerdtree#echo("Refreshing node. This could take a while...")
|
||||
call node.refresh()
|
||||
call b:NERDTree.render()
|
||||
redraw
|
||||
call nerdtree#echo("Refreshing node. This could take a while... DONE")
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#setupCommands() {{{1
|
||||
function! nerdtree#ui_glue#setupCommands()
|
||||
command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('<args>')
|
||||
command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('<args>')
|
||||
command! -n=0 -bar NERDTreeClose :call g:NERDTree.Close()
|
||||
command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('<args>')
|
||||
command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror()
|
||||
command! -n=0 -bar NERDTreeFind call s:findAndRevealPath()
|
||||
command! -n=0 -bar NERDTreeFocus call NERDTreeFocus()
|
||||
command! -n=0 -bar NERDTreeCWD call NERDTreeCWD()
|
||||
endfunction
|
||||
|
||||
" Function: s:SID() {{{1
|
||||
function s:SID()
|
||||
if !exists("s:sid")
|
||||
let s:sid = matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
|
||||
endif
|
||||
return s:sid
|
||||
endfun
|
||||
|
||||
" FUNCTION: s:showMenu(node) {{{1
|
||||
function! s:showMenu(node)
|
||||
let mc = g:NERDTreeMenuController.New(g:NERDTreeMenuItem.AllEnabled())
|
||||
call mc.showMenu()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleIgnoreFilter() {{{1
|
||||
function! s:toggleIgnoreFilter()
|
||||
call b:NERDTree.ui.toggleIgnoreFilter()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowBookmarks() {{{1
|
||||
function! s:toggleShowBookmarks()
|
||||
call b:NERDTree.ui.toggleShowBookmarks()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowFiles() {{{1
|
||||
function! s:toggleShowFiles()
|
||||
call b:NERDTree.ui.toggleShowFiles()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowHidden() {{{1
|
||||
" toggles the display of hidden files
|
||||
function! s:toggleShowHidden()
|
||||
call b:NERDTree.ui.toggleShowHidden()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleZoom() {{{1
|
||||
function! s:toggleZoom()
|
||||
call b:NERDTree.ui.toggleZoom()
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#ui_glue#upDir(keepState) {{{1
|
||||
"moves the tree up a level
|
||||
"
|
||||
"Args:
|
||||
"keepState: 1 if the current root should be left open when the tree is
|
||||
"re-rendered
|
||||
function! nerdtree#ui_glue#upDir(keepState)
|
||||
let cwd = b:NERDTreeRoot.path.str({'format': 'UI'})
|
||||
if cwd ==# "/" || cwd =~# '^[^/]..$'
|
||||
call nerdtree#echo("already at top dir")
|
||||
else
|
||||
if !a:keepState
|
||||
call b:NERDTreeRoot.close()
|
||||
endif
|
||||
|
||||
let oldRoot = b:NERDTreeRoot
|
||||
|
||||
if empty(b:NERDTreeRoot.parent)
|
||||
let path = b:NERDTreeRoot.path.getParent()
|
||||
let newRoot = g:NERDTreeDirNode.New(path)
|
||||
call newRoot.open()
|
||||
call newRoot.transplantChild(b:NERDTreeRoot)
|
||||
let b:NERDTreeRoot = newRoot
|
||||
else
|
||||
let b:NERDTreeRoot = b:NERDTreeRoot.parent
|
||||
endif
|
||||
|
||||
if g:NERDTreeChDirMode ==# 2
|
||||
call b:NERDTreeRoot.path.changeToDir()
|
||||
endif
|
||||
|
||||
call b:NERDTree.render()
|
||||
call oldRoot.putCursorHere(0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:upDirCurrentRootOpen() {{{1
|
||||
function! s:upDirCurrentRootOpen()
|
||||
call nerdtree#ui_glue#upDir(1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:upDirCurrentRootClosed() {{{1
|
||||
function! s:upDirCurrentRootClosed()
|
||||
call nerdtree#ui_glue#upDir(0)
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
@ -0,0 +1,13 @@
|
||||
"CLASS: Event
|
||||
"============================================================
|
||||
let s:Event = {}
|
||||
let g:NERDTreeEvent = s:Event
|
||||
|
||||
function! s:Event.New(nerdtree, subject, action, params) abort
|
||||
let newObj = copy(self)
|
||||
let newObj.nerdtree = a:nerdtree
|
||||
let newObj.subject = a:subject
|
||||
let newObj.action = a:action
|
||||
let newObj.params = a:params
|
||||
return newObj
|
||||
endfunction
|
@ -0,0 +1,56 @@
|
||||
"CLASS: FlagSet
|
||||
"============================================================
|
||||
let s:FlagSet = {}
|
||||
let g:NERDTreeFlagSet = s:FlagSet
|
||||
|
||||
"FUNCTION: FlagSet.addFlag(scope, flag) {{{1
|
||||
function! s:FlagSet.addFlag(scope, flag)
|
||||
let flags = self._flagsForScope(a:scope)
|
||||
if index(flags, a:flag) == -1
|
||||
call add(flags, a:flag)
|
||||
end
|
||||
endfunction
|
||||
|
||||
"FUNCTION: FlagSet.clearFlags(scope) {{{1
|
||||
function! s:FlagSet.clearFlags(scope)
|
||||
let self._flags[a:scope] = []
|
||||
endfunction
|
||||
|
||||
"FUNCTION: FlagSet._flagsForScope(scope) {{{1
|
||||
function! s:FlagSet._flagsForScope(scope)
|
||||
if !has_key(self._flags, a:scope)
|
||||
let self._flags[a:scope] = []
|
||||
endif
|
||||
return self._flags[a:scope]
|
||||
endfunction
|
||||
|
||||
"FUNCTION: FlagSet.New() {{{1
|
||||
function! s:FlagSet.New()
|
||||
let newObj = copy(self)
|
||||
let newObj._flags = {}
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
"FUNCTION: FlagSet.removeFlag(scope, flag) {{{1
|
||||
function! s:FlagSet.removeFlag(scope, flag)
|
||||
let flags = self._flagsForScope(a:scope)
|
||||
|
||||
let i = index(flags, a:flag)
|
||||
if i >= 0
|
||||
call remove(flags, i)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: FlagSet.renderToString() {{{1
|
||||
function! s:FlagSet.renderToString()
|
||||
let flagstring = ""
|
||||
for i in values(self._flags)
|
||||
let flagstring .= join(i)
|
||||
endfor
|
||||
|
||||
if len(flagstring) == 0
|
||||
return ""
|
||||
endif
|
||||
|
||||
return '[' . flagstring . ']'
|
||||
endfunction
|
@ -0,0 +1,137 @@
|
||||
"CLASS: NERDTree
|
||||
"============================================================
|
||||
let s:NERDTree = {}
|
||||
let g:NERDTree = s:NERDTree
|
||||
|
||||
"FUNCTION: s:NERDTree.AddPathFilter() {{{1
|
||||
function! s:NERDTree.AddPathFilter(callback)
|
||||
call add(s:NERDTree.PathFilters(), a:callback)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.Close() {{{1
|
||||
"Closes the primary NERD tree window for this tab
|
||||
function! s:NERDTree.Close()
|
||||
if !s:NERDTree.IsOpen()
|
||||
return
|
||||
endif
|
||||
|
||||
if winnr("$") != 1
|
||||
if winnr() == s:NERDTree.GetWinNum()
|
||||
call nerdtree#exec("wincmd p")
|
||||
let bufnr = bufnr("")
|
||||
call nerdtree#exec("wincmd p")
|
||||
else
|
||||
let bufnr = bufnr("")
|
||||
endif
|
||||
|
||||
call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w")
|
||||
close
|
||||
call nerdtree#exec(bufwinnr(bufnr) . " wincmd w")
|
||||
else
|
||||
close
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.CloseIfQuitOnOpen() {{{1
|
||||
"Closes the NERD tree window if the close on open option is set
|
||||
function! s:NERDTree.CloseIfQuitOnOpen()
|
||||
if g:NERDTreeQuitOnOpen && s:NERDTree.IsOpen()
|
||||
call s:NERDTree.Close()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.CursorToBookmarkTable(){{{1
|
||||
"Places the cursor at the top of the bookmarks table
|
||||
function! s:NERDTree.CursorToBookmarkTable()
|
||||
if !b:NERDTreeShowBookmarks
|
||||
throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active"
|
||||
endif
|
||||
|
||||
if g:NERDTreeMinimalUI
|
||||
return cursor(1, 2)
|
||||
endif
|
||||
|
||||
let rootNodeLine = b:NERDTree.ui.getRootLineNum()
|
||||
|
||||
let line = 1
|
||||
while getline(line) !~# '^>-\+Bookmarks-\+$'
|
||||
let line = line + 1
|
||||
if line >= rootNodeLine
|
||||
throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table"
|
||||
endif
|
||||
endwhile
|
||||
call cursor(line, 2)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.CursorToTreeWin(){{{1
|
||||
"Places the cursor in the nerd tree window
|
||||
function! s:NERDTree.CursorToTreeWin()
|
||||
call g:NERDTree.MustBeOpen()
|
||||
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w")
|
||||
endfunction
|
||||
|
||||
" Function: s:NERDTree.ExistsForBuffer() {{{1
|
||||
" Returns 1 if a nerd tree root exists in the current buffer
|
||||
function! s:NERDTree.ExistsForBuf()
|
||||
return exists("b:NERDTreeRoot")
|
||||
endfunction
|
||||
|
||||
" Function: s:NERDTree.ExistsForTab() {{{1
|
||||
" Returns 1 if a nerd tree root exists in the current tab
|
||||
function! s:NERDTree.ExistsForTab()
|
||||
return exists("t:NERDTreeBufName")
|
||||
endfunction
|
||||
|
||||
function! s:NERDTree.ForCurrentBuf()
|
||||
if s:NERDTree.ExistsForBuf()
|
||||
return b:NERDTree
|
||||
else
|
||||
return {}
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.GetWinNum() {{{1
|
||||
"gets the nerd tree window number for this tab
|
||||
function! s:NERDTree.GetWinNum()
|
||||
if exists("t:NERDTreeBufName")
|
||||
return bufwinnr(t:NERDTreeBufName)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.IsOpen() {{{1
|
||||
function! s:NERDTree.IsOpen()
|
||||
return s:NERDTree.GetWinNum() != -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.MustBeOpen() {{{1
|
||||
function! s:NERDTree.MustBeOpen()
|
||||
if !s:NERDTree.IsOpen()
|
||||
throw "NERDTree.TreeNotOpen"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.New() {{{1
|
||||
function! s:NERDTree.New(path)
|
||||
let newObj = copy(self)
|
||||
let newObj.ui = g:NERDTreeUI.New(newObj)
|
||||
let newObj.root = g:NERDTreeDirNode.New(a:path)
|
||||
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.PathFilters() {{{1
|
||||
function! s:NERDTree.PathFilters()
|
||||
if !exists('s:NERDTree._PathFilters')
|
||||
let s:NERDTree._PathFilters = []
|
||||
endif
|
||||
return s:NERDTree._PathFilters
|
||||
endfunction
|
||||
|
||||
|
||||
"FUNCTION: s:NERDTree.render() {{{1
|
||||
"A convenience function - since this is called often
|
||||
function! s:NERDTree.render()
|
||||
call self.ui.render()
|
||||
endfunction
|
@ -0,0 +1,35 @@
|
||||
"CLASS: Notifier
|
||||
"============================================================
|
||||
let s:Notifier = {}
|
||||
|
||||
function! s:Notifier.AddListener(event, funcname)
|
||||
let listeners = s:Notifier.GetListenersForEvent(a:event)
|
||||
if listeners == []
|
||||
let listenersMap = s:Notifier.GetListenersMap()
|
||||
let listenersMap[a:event] = listeners
|
||||
endif
|
||||
call add(listeners, a:funcname)
|
||||
endfunction
|
||||
|
||||
function! s:Notifier.NotifyListeners(event, path, params)
|
||||
let event = g:NERDTreeEvent.New(b:NERDTree, a:path, a:event, a:params)
|
||||
|
||||
for listener in s:Notifier.GetListenersForEvent(a:event)
|
||||
call {listener}(event)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:Notifier.GetListenersMap()
|
||||
if !exists("s:refreshListenersMap")
|
||||
let s:refreshListenersMap = {}
|
||||
endif
|
||||
return s:refreshListenersMap
|
||||
endfunction
|
||||
|
||||
function! s:Notifier.GetListenersForEvent(name)
|
||||
let listenersMap = s:Notifier.GetListenersMap()
|
||||
return get(listenersMap, a:name, [])
|
||||
endfunction
|
||||
|
||||
let g:NERDTreePathNotifier = deepcopy(s:Notifier)
|
||||
|
@ -0,0 +1,506 @@
|
||||
"CLASS: UI
|
||||
"============================================================
|
||||
let s:UI = {}
|
||||
let g:NERDTreeUI = s:UI
|
||||
|
||||
"FUNCTION: s:UI.centerView() {{{2
|
||||
"centers the nerd tree window around the cursor (provided the nerd tree
|
||||
"options permit)
|
||||
function! s:UI.centerView()
|
||||
if g:NERDTreeAutoCenter
|
||||
let current_line = winline()
|
||||
let lines_to_top = current_line
|
||||
let lines_to_bottom = winheight(g:NERDTree.GetWinNum()) - current_line
|
||||
if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold
|
||||
normal! zz
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._dumpHelp {{{1
|
||||
"prints out the quick help
|
||||
function! s:UI._dumpHelp()
|
||||
let old_h = @h
|
||||
if b:treeShowHelp ==# 1
|
||||
let @h= "\" NERD tree (" . nerdtree#version() . ") quickhelp~\n"
|
||||
let @h=@h."\" ============================\n"
|
||||
let @h=@h."\" File node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n"
|
||||
let @h=@h."\" <CR>,\n"
|
||||
if b:NERDTreeType ==# "primary"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n"
|
||||
else
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n"
|
||||
endif
|
||||
if b:NERDTreeType ==# "primary"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n"
|
||||
endif
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
|
||||
let @h=@h."\" middle-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenSplit .": open split\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreviewSplit .": preview split\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenVSplit .": open vsplit\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreviewVSplit .": preview vsplit\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Directory node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open & close node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseDir .": close parent of node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n"
|
||||
let @h=@h."\" current node recursively\n"
|
||||
let @h=@h."\" middle-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenExpl.": explore selected dir\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark table mappings~\n"
|
||||
let @h=@h."\" double-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open bookmark\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapDeleteBookmark .": delete bookmark\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Tree navigation mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpParent .": go to parent\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpFirstChild .": go to first child\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpLastChild .": go to last child\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpNextSibling .": go to next sibling\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpPrevSibling .": go to prev sibling\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Filesystem mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapChangeRoot .": change tree root to the\n"
|
||||
let @h=@h."\" selected dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapUpdir .": move tree root up a dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapUpdirKeepOpen .": move tree root up a dir\n"
|
||||
let @h=@h."\" but leave old root open\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapRefresh .": refresh cursor dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapRefreshRoot .": refresh current root\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapMenu .": Show menu\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapChdir .":change the CWD to the\n"
|
||||
let @h=@h."\" selected dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCWD .":change tree root to CWD\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Tree filtering mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n"
|
||||
|
||||
"add quickhelp entries for each custom key map
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Custom mappings~\n"
|
||||
for i in g:NERDTreeKeyMap.All()
|
||||
if !empty(i.quickhelpText)
|
||||
let @h=@h."\" ". i.key .": ". i.quickhelpText ."\n"
|
||||
endif
|
||||
endfor
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Other mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapQuit .": Close the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleZoom .": Zoom (maximize-minimize)\n"
|
||||
let @h=@h."\" the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapHelp .": toggle help\n"
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark commands~\n"
|
||||
let @h=@h."\" :Bookmark [<name>]\n"
|
||||
let @h=@h."\" :BookmarkToRoot <name>\n"
|
||||
let @h=@h."\" :RevealBookmark <name>\n"
|
||||
let @h=@h."\" :OpenBookmark <name>\n"
|
||||
let @h=@h."\" :ClearBookmarks [<names>]\n"
|
||||
let @h=@h."\" :ClearAllBookmarks\n"
|
||||
silent! put h
|
||||
elseif g:NERDTreeMinimalUI == 0
|
||||
let @h="\" Press ". g:NERDTreeMapHelp ." for help\n"
|
||||
silent! put h
|
||||
endif
|
||||
|
||||
let @h = old_h
|
||||
endfunction
|
||||
|
||||
|
||||
"FUNCTION: s:UI.new(nerdtree) {{{1
|
||||
function! s:UI.New(nerdtree)
|
||||
let newObj = copy(self)
|
||||
let newObj.nerdtree = a:nerdtree
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.getPath(ln) {{{1
|
||||
"Gets the full path to the node that is rendered on the given line number
|
||||
"
|
||||
"Args:
|
||||
"ln: the line number to get the path for
|
||||
"
|
||||
"Return:
|
||||
"A path if a node was selected, {} if nothing is selected.
|
||||
"If the 'up a dir' line was selected then the path to the parent of the
|
||||
"current root is returned
|
||||
function! s:UI.getPath(ln)
|
||||
let line = getline(a:ln)
|
||||
|
||||
let rootLine = self.getRootLineNum()
|
||||
|
||||
"check to see if we have the root node
|
||||
if a:ln == rootLine
|
||||
return b:NERDTreeRoot.path
|
||||
endif
|
||||
|
||||
if !g:NERDTreeDirArrows
|
||||
" in case called from outside the tree
|
||||
if line !~# '^ *[|`'.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.' ]' || line =~# '^$'
|
||||
return {}
|
||||
endif
|
||||
endif
|
||||
|
||||
if line ==# s:UI.UpDirLine()
|
||||
return b:NERDTreeRoot.path.getParent()
|
||||
endif
|
||||
|
||||
let indent = self._indentLevelFor(line)
|
||||
|
||||
"remove the tree parts and the leading space
|
||||
let curFile = self._stripMarkup(line, 0)
|
||||
|
||||
let wasdir = 0
|
||||
if curFile =~# '/$'
|
||||
let wasdir = 1
|
||||
let curFile = substitute(curFile, '/\?$', '/', "")
|
||||
endif
|
||||
|
||||
let dir = ""
|
||||
let lnum = a:ln
|
||||
while lnum > 0
|
||||
let lnum = lnum - 1
|
||||
let curLine = getline(lnum)
|
||||
let curLineStripped = self._stripMarkup(curLine, 1)
|
||||
|
||||
"have we reached the top of the tree?
|
||||
if lnum == rootLine
|
||||
let dir = b:NERDTreeRoot.path.str({'format': 'UI'}) . dir
|
||||
break
|
||||
endif
|
||||
if curLineStripped =~# '/$'
|
||||
let lpindent = self._indentLevelFor(curLine)
|
||||
if lpindent < indent
|
||||
let indent = indent - 1
|
||||
|
||||
let dir = substitute (curLineStripped,'^\\', "", "") . dir
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
let curFile = b:NERDTreeRoot.path.drive . dir . curFile
|
||||
let toReturn = g:NERDTreePath.New(curFile)
|
||||
return toReturn
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.getLineNum(file_node){{{1
|
||||
"returns the line number this node is rendered on, or -1 if it isnt rendered
|
||||
function! s:UI.getLineNum(file_node)
|
||||
"if the node is the root then return the root line no.
|
||||
if a:file_node.isRoot()
|
||||
return b:NERDTree.ui.getRootLineNum()
|
||||
endif
|
||||
|
||||
let totalLines = line("$")
|
||||
|
||||
"the path components we have matched so far
|
||||
let pathcomponents = [substitute(b:NERDTreeRoot.path.str({'format': 'UI'}), '/ *$', '', '')]
|
||||
"the index of the component we are searching for
|
||||
let curPathComponent = 1
|
||||
|
||||
let fullpath = a:file_node.path.str({'format': 'UI'})
|
||||
|
||||
let lnum = b:NERDTree.ui.getRootLineNum()
|
||||
while lnum > 0
|
||||
let lnum = lnum + 1
|
||||
"have we reached the bottom of the tree?
|
||||
if lnum ==# totalLines+1
|
||||
return -1
|
||||
endif
|
||||
|
||||
let curLine = getline(lnum)
|
||||
|
||||
let indent = self._indentLevelFor(curLine)
|
||||
if indent ==# curPathComponent
|
||||
let curLine = self._stripMarkup(curLine, 1)
|
||||
|
||||
let curPath = join(pathcomponents, '/') . '/' . curLine
|
||||
if stridx(fullpath, curPath, 0) ==# 0
|
||||
if fullpath ==# curPath || strpart(fullpath, len(curPath)-1,1) ==# '/'
|
||||
let curLine = substitute(curLine, '/ *$', '', '')
|
||||
call add(pathcomponents, curLine)
|
||||
let curPathComponent = curPathComponent + 1
|
||||
|
||||
if fullpath ==# curPath
|
||||
return lnum
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.getRootLineNum(){{{1
|
||||
"gets the line number of the root node
|
||||
function! s:UI.getRootLineNum()
|
||||
let rootLine = 1
|
||||
while getline(rootLine) !~# '^\(/\|<\)'
|
||||
let rootLine = rootLine + 1
|
||||
endwhile
|
||||
return rootLine
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._indentLevelFor(line) {{{1
|
||||
function! s:UI._indentLevelFor(line)
|
||||
let level = match(a:line, '[^ \-+~'.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.'`|]') / s:UI.IndentWid()
|
||||
" check if line includes arrows
|
||||
if match(a:line, '['.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.']') > -1
|
||||
" decrement level as arrow uses 3 ascii chars
|
||||
let level = level - 1
|
||||
endif
|
||||
return level
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.IndentWid() {{{1
|
||||
function! s:UI.IndentWid()
|
||||
return 2
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.MarkupReg() {{{1
|
||||
function! s:UI.MarkupReg()
|
||||
if g:NERDTreeDirArrows
|
||||
return '^\(['.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.'] \| \+['.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.'] \| \+\)'
|
||||
endif
|
||||
|
||||
return '^[ `|]*[\-+~]'
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._renderBookmarks {{{1
|
||||
function! s:UI._renderBookmarks()
|
||||
|
||||
if g:NERDTreeMinimalUI == 0
|
||||
call setline(line(".")+1, ">----------Bookmarks----------")
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
for i in g:NERDTreeBookmark.Bookmarks()
|
||||
call setline(line(".")+1, i.str())
|
||||
call cursor(line(".")+1, col("."))
|
||||
endfor
|
||||
|
||||
call setline(line(".")+1, '')
|
||||
call cursor(line(".")+1, col("."))
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.restoreScreenState() {{{1
|
||||
"
|
||||
"Sets the screen state back to what it was when nerdtree#saveScreenState was last
|
||||
"called.
|
||||
"
|
||||
"Assumes the cursor is in the NERDTree window
|
||||
function! s:UI.restoreScreenState()
|
||||
if !has_key(self, '_screenState')
|
||||
return
|
||||
endif
|
||||
exec("silent vertical resize " . self._screenState['oldWindowSize'])
|
||||
|
||||
let old_scrolloff=&scrolloff
|
||||
let &scrolloff=0
|
||||
call cursor(self._screenState['oldTopLine'], 0)
|
||||
normal! zt
|
||||
call setpos(".", self._screenState['oldPos'])
|
||||
let &scrolloff=old_scrolloff
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.saveScreenState() {{{1
|
||||
"Saves the current cursor position in the current buffer and the window
|
||||
"scroll position
|
||||
function! s:UI.saveScreenState()
|
||||
let win = winnr()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
let self._screenState = {}
|
||||
let self._screenState['oldPos'] = getpos(".")
|
||||
let self._screenState['oldTopLine'] = line("w0")
|
||||
let self._screenState['oldWindowSize']= winwidth("")
|
||||
call nerdtree#exec(win . "wincmd w")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._stripMarkup(line, removeLeadingSpaces){{{1
|
||||
"returns the given line with all the tree parts stripped off
|
||||
"
|
||||
"Args:
|
||||
"line: the subject line
|
||||
"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces =
|
||||
"any spaces before the actual text of the node)
|
||||
function! s:UI._stripMarkup(line, removeLeadingSpaces)
|
||||
let line = a:line
|
||||
"remove the tree parts and the leading space
|
||||
let line = substitute (line, g:NERDTreeUI.MarkupReg(),"","")
|
||||
|
||||
"strip off any read only flag
|
||||
let line = substitute (line, ' \[RO\]', "","")
|
||||
|
||||
"strip off any bookmark flags
|
||||
let line = substitute (line, ' {[^}]*}', "","")
|
||||
|
||||
"strip off any executable flags
|
||||
let line = substitute (line, '*\ze\($\| \)', "","")
|
||||
|
||||
"strip off any generic flags
|
||||
let line = substitute (line, '\[[^]]*\]', "","")
|
||||
|
||||
let wasdir = 0
|
||||
if line =~# '/$'
|
||||
let wasdir = 1
|
||||
endif
|
||||
let line = substitute (line,' -> .*',"","") " remove link to
|
||||
if wasdir ==# 1
|
||||
let line = substitute (line, '/\?$', '/', "")
|
||||
endif
|
||||
|
||||
if a:removeLeadingSpaces
|
||||
let line = substitute (line, '^ *', '', '')
|
||||
endif
|
||||
|
||||
return line
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.render() {{{1
|
||||
function! s:UI.render()
|
||||
setlocal modifiable
|
||||
|
||||
"remember the top line of the buffer and the current line so we can
|
||||
"restore the view exactly how it was
|
||||
let curLine = line(".")
|
||||
let curCol = col(".")
|
||||
let topLine = line("w0")
|
||||
|
||||
"delete all lines in the buffer (being careful not to clobber a register)
|
||||
silent 1,$delete _
|
||||
|
||||
call self._dumpHelp()
|
||||
|
||||
"delete the blank line before the help and add one after it
|
||||
if g:NERDTreeMinimalUI == 0
|
||||
call setline(line(".")+1, "")
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
if b:NERDTreeShowBookmarks
|
||||
call self._renderBookmarks()
|
||||
endif
|
||||
|
||||
"add the 'up a dir' line
|
||||
if !g:NERDTreeMinimalUI
|
||||
call setline(line(".")+1, s:UI.UpDirLine())
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
"draw the header line
|
||||
let header = b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
|
||||
call setline(line(".")+1, header)
|
||||
call cursor(line(".")+1, col("."))
|
||||
|
||||
"draw the tree
|
||||
let old_o = @o
|
||||
let @o = b:NERDTreeRoot.renderToString()
|
||||
silent put o
|
||||
let @o = old_o
|
||||
|
||||
"delete the blank line at the top of the buffer
|
||||
silent 1,1delete _
|
||||
|
||||
"restore the view
|
||||
let old_scrolloff=&scrolloff
|
||||
let &scrolloff=0
|
||||
call cursor(topLine, 1)
|
||||
normal! zt
|
||||
call cursor(curLine, curCol)
|
||||
let &scrolloff = old_scrolloff
|
||||
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
|
||||
|
||||
"FUNCTION: UI.renderViewSavingPosition {{{1
|
||||
"Renders the tree and ensures the cursor stays on the current node or the
|
||||
"current nodes parent if it is no longer available upon re-rendering
|
||||
function! s:UI.renderViewSavingPosition()
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
|
||||
"go up the tree till we find a node that will be visible or till we run
|
||||
"out of nodes
|
||||
while currentNode != {} && !currentNode.isVisible() && !currentNode.isRoot()
|
||||
let currentNode = currentNode.parent
|
||||
endwhile
|
||||
|
||||
call b:NERDTree.render()
|
||||
|
||||
if currentNode != {}
|
||||
call currentNode.putCursorHere(0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleIgnoreFilter() {{{1
|
||||
" toggles the use of the NERDTreeIgnore option
|
||||
function! s:UI.toggleIgnoreFilter()
|
||||
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled
|
||||
call b:NERDTree.ui.renderViewSavingPosition()
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
|
||||
" toggles the display of bookmarks
|
||||
function! s:UI.toggleShowBookmarks()
|
||||
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
|
||||
if b:NERDTreeShowBookmarks
|
||||
call b:NERDTree.render()
|
||||
call g:NERDTree.CursorToBookmarkTable()
|
||||
else
|
||||
call b:NERDTree.ui.renderViewSavingPosition()
|
||||
endif
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleShowFiles() {{{1
|
||||
" toggles the display of hidden files
|
||||
function! s:UI.toggleShowFiles()
|
||||
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles
|
||||
call b:NERDTree.ui.renderViewSavingPosition()
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleShowHidden() {{{1
|
||||
" toggles the display of hidden files
|
||||
function! s:UI.toggleShowHidden()
|
||||
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden
|
||||
call b:NERDTree.ui.renderViewSavingPosition()
|
||||
call self.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleZoom() {{{1
|
||||
" zoom (maximize/minimize) the NERDTree window
|
||||
function! s:UI.toggleZoom()
|
||||
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed
|
||||
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
|
||||
exec "silent vertical resize ". size
|
||||
let b:NERDTreeZoomed = 0
|
||||
else
|
||||
exec "vertical resize"
|
||||
let b:NERDTreeZoomed = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.UpDirLine() {{{1
|
||||
function! s:UI.UpDirLine()
|
||||
return '.. (up a dir)'
|
||||
endfunction
|
Loading…
Reference in New Issue