mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/nerdtree/lib/nerdtree/ui.vim

526 lines
18 KiB
VimL
Raw Normal View History

2018-02-04 06:35:08 -05:00
" ============================================================================
" CLASS: UI
" ============================================================================
2014-08-03 18:02:51 -04:00
let s:UI = {}
let g:NERDTreeUI = s:UI
2019-08-22 11:36:17 -04:00
" FUNCTION: s:UI.centerView() {{{1
2018-02-04 06:35:08 -05:00
" centers the nerd tree window around the cursor (provided the nerd tree
" options permit)
2014-08-03 18:02:51 -04:00
function! s:UI.centerView()
if g:NERDTreeAutoCenter
let current_line = winline()
let lines_to_top = current_line
2015-07-13 06:22:46 -04:00
let lines_to_bottom = winheight(g:NERDTree.GetWinNum()) - current_line
2014-08-03 18:02:51 -04:00
if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold
normal! zz
endif
endif
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI._dumpHelp {{{1
" prints out the quick help
2015-07-13 06:22:46 -04:00
function! s:UI._dumpHelp()
2015-12-08 08:20:04 -05:00
if self.getShowHelp()
2017-09-02 06:43:18 -04:00
let help = "\" NERDTree (" . nerdtree#version() . ") quickhelp~\n"
2017-03-07 12:04:28 -05:00
let help .= "\" ============================\n"
let help .= "\" File node mappings~\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. (g:NERDTreeMouseMode ==# 3 ? 'single' : 'double') ."-click,\n"
2015-12-08 08:20:04 -05:00
if self.nerdtree.isTabTree()
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapActivateNode .": open in prev window\n"
2015-07-13 06:22:46 -04:00
else
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapActivateNode .": open in current window\n"
2015-07-13 06:22:46 -04:00
endif
2015-12-08 08:20:04 -05:00
if self.nerdtree.isTabTree()
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapPreview .": preview\n"
2015-07-13 06:22:46 -04:00
endif
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapOpenInTab.": open in new tab\n"
let help .= '" '. g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
2017-03-07 12:04:28 -05:00
let help .= "\" middle-click,\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapOpenSplit .": open split\n"
let help .= '" '. g:NERDTreeMapPreviewSplit .": preview split\n"
let help .= '" '. g:NERDTreeMapOpenVSplit .": open vsplit\n"
let help .= '" '. g:NERDTreeMapPreviewVSplit .": preview vsplit\n"
let help .= '" '. g:NERDTreeMapCustomOpen .": custom open\n"
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Directory node mappings~\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. (g:NERDTreeMouseMode ==# 1 ? 'double' : 'single') ."-click,\n"
let help .= '" '. g:NERDTreeMapActivateNode .": open & close 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:NERDTreeMapCustomOpen .": custom open\n"
let help .= '" '. g:NERDTreeMapCloseDir .": close parent of node\n"
let help .= '" '. g:NERDTreeMapCloseChildren .": close all child nodes of\n"
2017-03-07 12:04:28 -05:00
let help .= "\" current node recursively\n"
let help .= "\" middle-click,\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapOpenExpl.": explore selected dir\n"
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Bookmark table mappings~\n"
let help .= "\" double-click,\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapActivateNode .": open bookmark\n"
let help .= '" '. g:NERDTreeMapPreview .": preview file\n"
let help .= '" '. g:NERDTreeMapPreview .": find dir in tree\n"
let help .= '" '. g:NERDTreeMapOpenInTab.": open in new tab\n"
let help .= '" '. g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
let help .= '" '. g:NERDTreeMapCustomOpen .": custom open\n"
let help .= '" '. g:NERDTreeMapDeleteBookmark .": delete bookmark\n"
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Tree navigation mappings~\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapJumpRoot .": go to root\n"
let help .= '" '. g:NERDTreeMapJumpParent .": go to parent\n"
let help .= '" '. g:NERDTreeMapJumpFirstChild .": go to first child\n"
let help .= '" '. g:NERDTreeMapJumpLastChild .": go to last child\n"
let help .= '" '. g:NERDTreeMapJumpNextSibling .": go to next sibling\n"
let help .= '" '. g:NERDTreeMapJumpPrevSibling .": go to prev sibling\n"
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Filesystem mappings~\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapChangeRoot .": change tree root to the\n"
2017-03-07 12:04:28 -05:00
let help .= "\" selected dir\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapUpdir .": move tree root up a dir\n"
let help .= '" '. g:NERDTreeMapUpdirKeepOpen .": move tree root up a dir\n"
2017-03-07 12:04:28 -05:00
let help .= "\" but leave old root open\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapRefresh .": refresh cursor dir\n"
let help .= '" '. g:NERDTreeMapRefreshRoot .": refresh current root\n"
let help .= '" '. g:NERDTreeMapMenu .": Show menu\n"
let help .= '" '. g:NERDTreeMapChdir .":change the CWD to the\n"
2017-03-07 12:04:28 -05:00
let help .= "\" selected dir\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapCWD .":change tree root to CWD\n"
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Tree filtering mappings~\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapToggleHidden .': hidden files (' . (self.getShowHidden() ? 'on' : 'off') . ")\n"
let help .= '" '. g:NERDTreeMapToggleFilters .': file filters (' . (self.isIgnoreFilterEnabled() ? 'on' : 'off') . ")\n"
let help .= '" '. g:NERDTreeMapToggleFiles .': files (' . (self.getShowFiles() ? 'on' : 'off') . ")\n"
let help .= '" '. g:NERDTreeMapToggleBookmarks .': bookmarks (' . (self.getShowBookmarks() ? 'on' : 'off') . ")\n"
2015-07-13 06:22:46 -04:00
2018-02-04 06:35:08 -05:00
" add quickhelp entries for each custom key map
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Custom mappings~\n"
2015-07-13 06:22:46 -04:00
for i in g:NERDTreeKeyMap.All()
if !empty(i.quickhelpText)
2020-01-07 07:45:07 -05:00
let help .= '" '. i.key .': '. i.quickhelpText ."\n"
2015-07-13 06:22:46 -04:00
endif
endfor
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Other mappings~\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapQuit .": Close the NERDTree window\n"
let help .= '" '. g:NERDTreeMapToggleZoom .": Zoom (maximize-minimize)\n"
2017-03-07 12:04:28 -05:00
let help .= "\" the NERDTree window\n"
2020-01-07 07:45:07 -05:00
let help .= '" '. g:NERDTreeMapHelp .": toggle help\n"
2017-03-07 12:04:28 -05:00
let help .= "\"\n\" ----------------------------\n"
let help .= "\" Bookmark commands~\n"
let help .= "\" :Bookmark [<name>]\n"
let help .= "\" :BookmarkToRoot <name>\n"
let help .= "\" :RevealBookmark <name>\n"
let help .= "\" :OpenBookmark <name>\n"
let help .= "\" :ClearBookmarks [<names>]\n"
let help .= "\" :ClearAllBookmarks\n"
2019-03-08 06:04:56 -05:00
let help .= "\" :ReadBookmarks\n"
let help .= "\" :WriteBookmarks\n"
let help .= "\" :EditBookmarks\n"
2017-03-07 12:04:28 -05:00
silent! put =help
2015-12-08 08:20:04 -05:00
elseif !self.isMinimal()
2020-01-07 07:45:07 -05:00
let help ='" Press '. g:NERDTreeMapHelp ." for help\n"
2017-03-07 12:04:28 -05:00
silent! put =help
2015-07-13 06:22:46 -04:00
endif
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.new(nerdtree) {{{1
2014-08-03 18:02:51 -04:00
function! s:UI.New(nerdtree)
let newObj = copy(self)
let newObj.nerdtree = a:nerdtree
2015-12-08 08:20:04 -05:00
let newObj._showHelp = 0
let newObj._ignoreEnabled = 1
let newObj._showFiles = g:NERDTreeShowFiles
let newObj._showHidden = g:NERDTreeShowHidden
let newObj._showBookmarks = g:NERDTreeShowBookmarks
2014-08-03 18:02:51 -04:00
return newObj
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.getPath(ln) {{{1
2020-01-07 07:45:07 -05:00
" Return the Path object for the node that is rendered on the given line
" number. If the 'up a dir' line is selected, return the Path object for
2018-02-04 06:35:08 -05:00
" the parent of the root. Return the empty dictionary if the given line
" does not reference a tree node.
2014-08-03 18:02:51 -04:00
function! s:UI.getPath(ln)
let line = getline(a:ln)
let rootLine = self.getRootLineNum()
2020-01-07 07:45:07 -05:00
if a:ln ==# rootLine
2015-12-08 08:20:04 -05:00
return self.nerdtree.root.path
2014-08-03 18:02:51 -04:00
endif
2015-07-13 06:22:46 -04:00
if line ==# s:UI.UpDirLine()
2015-12-08 08:20:04 -05:00
return self.nerdtree.root.path.getParent()
2014-08-03 18:02:51 -04:00
endif
2018-02-04 06:35:08 -05:00
if a:ln < rootLine
return {}
endif
2014-08-03 18:02:51 -04:00
let indent = self._indentLevelFor(line)
2018-02-04 06:35:08 -05:00
" remove the tree parts and the leading space
let curFile = self._stripMarkup(line)
2014-08-03 18:02:51 -04:00
2020-01-07 07:45:07 -05:00
let dir = ''
2014-08-03 18:02:51 -04:00
let lnum = a:ln
while lnum > 0
let lnum = lnum - 1
let curLine = getline(lnum)
let curLineStripped = self._stripMarkup(curLine)
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" have we reached the top of the tree?
2020-01-07 07:45:07 -05:00
if lnum ==# rootLine
2015-12-08 08:20:04 -05:00
let dir = self.nerdtree.root.path.str({'format': 'UI'}) . dir
2014-08-03 18:02:51 -04:00
break
endif
if curLineStripped =~# '/$'
let lpindent = self._indentLevelFor(curLine)
if lpindent < indent
let indent = indent - 1
2020-01-07 07:45:07 -05:00
let dir = substitute (curLineStripped,'^\\', '', '') . dir
2014-08-03 18:02:51 -04:00
continue
endif
endif
endwhile
2015-12-08 08:20:04 -05:00
let curFile = self.nerdtree.root.path.drive . dir . curFile
2014-08-03 18:02:51 -04:00
let toReturn = g:NERDTreePath.New(curFile)
return toReturn
endfunction
2018-09-24 20:40:17 -04:00
" FUNCTION: s:UI.getLineNum(node) {{{1
" Return the line number where the given node is rendered. Return -1 if the
" given node is not visible.
function! s:UI.getLineNum(node)
if a:node.isRoot()
2015-12-08 08:20:04 -05:00
return self.getRootLineNum()
2014-08-03 18:02:51 -04:00
endif
2018-09-24 20:40:17 -04:00
let l:pathComponents = [substitute(self.nerdtree.root.path.str({'format': 'UI'}), '/\s*$', '', '')]
let l:currentPathComponent = 1
2014-08-03 18:02:51 -04:00
2018-09-24 20:40:17 -04:00
let l:fullPath = a:node.path.str({'format': 'UI'})
2014-08-03 18:02:51 -04:00
2018-09-24 20:40:17 -04:00
for l:lineNumber in range(self.getRootLineNum() + 1, line('$'))
let l:currentLine = getline(l:lineNumber)
let l:indentLevel = self._indentLevelFor(l:currentLine)
2014-08-03 18:02:51 -04:00
2020-01-07 07:45:07 -05:00
if l:indentLevel !=# l:currentPathComponent
2018-09-24 20:40:17 -04:00
continue
2014-08-03 18:02:51 -04:00
endif
2018-09-24 20:40:17 -04:00
let l:currentLine = self._stripMarkup(l:currentLine)
let l:currentPath = join(l:pathComponents, '/') . '/' . l:currentLine
2014-08-03 18:02:51 -04:00
2020-01-07 07:45:07 -05:00
" Directories: If the current path 'starts with' the full path, then
2018-09-24 20:40:17 -04:00
" either the paths are equal or the line is a cascade containing the
" full path.
2020-01-07 07:45:07 -05:00
if l:fullPath[-1:] ==# '/' && stridx(l:currentPath, l:fullPath) ==# 0
2018-09-24 20:40:17 -04:00
return l:lineNumber
2014-08-03 18:02:51 -04:00
endif
2018-09-24 20:40:17 -04:00
" Files: The paths must exactly match.
if l:fullPath ==# l:currentPath
return l:lineNumber
endif
" Otherwise: If the full path starts with the current path and the
" current path is a directory, we add a new path component.
2020-01-07 07:45:07 -05:00
if stridx(l:fullPath, l:currentPath) ==# 0 && l:currentPath[-1:] ==# '/'
2018-09-24 20:40:17 -04:00
let l:currentLine = substitute(l:currentLine, '/\s*$', '', '')
call add(l:pathComponents, l:currentLine)
let l:currentPathComponent += 1
endif
endfor
2014-08-03 18:02:51 -04:00
return -1
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.getRootLineNum(){{{1
" gets the line number of the root node
2014-08-03 18:02:51 -04:00
function! s:UI.getRootLineNum()
let rootLine = 1
2019-08-22 11:36:17 -04:00
while rootLine <= line('$') && getline(rootLine) !~# '^\(/\|<\)'
2014-08-03 18:02:51 -04:00
let rootLine = rootLine + 1
endwhile
return rootLine
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.getShowBookmarks() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.getShowBookmarks()
return self._showBookmarks
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.getShowFiles() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.getShowFiles()
return self._showFiles
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.getShowHelp() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.getShowHelp()
return self._showHelp
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.getShowHidden() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.getShowHidden()
return self._showHidden
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI._indentLevelFor(line) {{{1
2014-08-03 18:02:51 -04:00
function! s:UI._indentLevelFor(line)
2019-05-17 10:09:13 -04:00
" Replace multi-character DirArrows with a single space so the
" indentation calculation doesn't get messed up.
let l:line = substitute(substitute(a:line, '\V'.g:NERDTreeDirArrowExpandable, ' ', ''), '\V'.g:NERDTreeDirArrowCollapsible, ' ', '')
let leadChars = match(l:line, '\M\[^ ]')
2015-12-08 08:20:04 -05:00
return leadChars / s:UI.IndentWid()
2014-08-03 18:02:51 -04:00
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.IndentWid() {{{1
2015-07-13 06:22:46 -04:00
function! s:UI.IndentWid()
return 2
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.isIgnoreFilterEnabled() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.isIgnoreFilterEnabled()
2020-01-07 07:45:07 -05:00
return self._ignoreEnabled ==# 1
2015-12-08 08:20:04 -05:00
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.isMinimal() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.isMinimal()
return g:NERDTreeMinimalUI
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.MarkupReg() {{{1
2015-07-13 06:22:46 -04:00
function! s:UI.MarkupReg()
2018-11-01 06:03:42 -04:00
return '^ *['.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.']\? '
2015-07-13 06:22:46 -04:00
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI._renderBookmarks {{{1
2015-07-13 06:22:46 -04:00
function! s:UI._renderBookmarks()
2015-12-08 08:20:04 -05:00
if !self.isMinimal()
2020-01-07 07:45:07 -05:00
call setline(line('.')+1, '>----------Bookmarks----------')
call cursor(line('.')+1, col('.'))
2015-07-13 06:22:46 -04:00
endif
2020-01-07 07:45:07 -05:00
if g:NERDTreeBookmarksSort ==# 1 || g:NERDTreeBookmarksSort ==# 2
2017-07-06 08:57:35 -04:00
call g:NERDTreeBookmark.SortBookmarksList()
endif
2015-07-13 06:22:46 -04:00
for i in g:NERDTreeBookmark.Bookmarks()
2020-01-07 07:45:07 -05:00
call setline(line('.')+1, i.str())
call cursor(line('.')+1, col('.'))
2015-07-13 06:22:46 -04:00
endfor
2020-01-07 07:45:07 -05:00
call setline(line('.')+1, '')
call cursor(line('.')+1, col('.'))
2015-07-13 06:22:46 -04:00
endfunction
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.restoreScreenState() {{{1
2014-08-03 18:02:51 -04:00
"
2018-02-04 06:35:08 -05:00
" Sets the screen state back to what it was when nerdtree#saveScreenState was last
" called.
2014-08-03 18:02:51 -04:00
"
2018-02-04 06:35:08 -05:00
" Assumes the cursor is in the NERDTree window
2014-08-03 18:02:51 -04:00
function! s:UI.restoreScreenState()
if !has_key(self, '_screenState')
return
endif
2020-01-07 07:45:07 -05:00
call nerdtree#exec('silent vertical resize ' . self._screenState['oldWindowSize'], 1)
2014-08-03 18:02:51 -04:00
let old_scrolloff=&scrolloff
let &scrolloff=0
call cursor(self._screenState['oldTopLine'], 0)
normal! zt
2020-01-07 07:45:07 -05:00
call setpos('.', self._screenState['oldPos'])
2014-08-03 18:02:51 -04:00
let &scrolloff=old_scrolloff
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.saveScreenState() {{{1
" Saves the current cursor position in the current buffer and the window
" scroll position
2014-08-03 18:02:51 -04:00
function! s:UI.saveScreenState()
let win = winnr()
2015-07-13 06:22:46 -04:00
let self._screenState = {}
2019-11-16 10:28:42 -05:00
try
call g:NERDTree.CursorToTreeWin()
2020-01-07 07:45:07 -05:00
let self._screenState['oldPos'] = getpos('.')
let self._screenState['oldTopLine'] = line('w0')
let self._screenState['oldWindowSize']= winwidth('')
call nerdtree#exec(win . 'wincmd w', 1)
2019-11-16 10:28:42 -05:00
catch
endtry
2014-08-03 18:02:51 -04:00
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.setShowHidden(val) {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.setShowHidden(val)
let self._showHidden = a:val
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI._stripMarkup(line){{{1
2018-11-01 06:03:42 -04:00
" find the filename in the given line, and return it.
2015-07-13 06:22:46 -04:00
"
2018-02-04 06:35:08 -05:00
" Args:
" line: the subject line
function! s:UI._stripMarkup(line)
2018-11-01 06:03:42 -04:00
let l:line = substitute(a:line, '^.\{-}' . g:NERDTreeNodeDelimiter, '', '')
return substitute(l:line, g:NERDTreeNodeDelimiter.'.*$', '', '')
2015-07-13 06:22:46 -04:00
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.render() {{{1
2014-08-03 18:02:51 -04:00
function! s:UI.render()
2018-06-14 06:31:12 -04:00
setlocal noreadonly modifiable
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" remember the top line of the buffer and the current line so we can
" restore the view exactly how it was
2020-01-07 07:45:07 -05:00
let curLine = line('.')
let curCol = col('.')
let topLine = line('w0')
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" delete all lines in the buffer (being careful not to clobber a register)
2014-08-03 18:02:51 -04:00
silent 1,$delete _
2015-07-13 06:22:46 -04:00
call self._dumpHelp()
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" delete the blank line before the help and add one after it
2015-12-08 08:20:04 -05:00
if !self.isMinimal()
2020-01-07 07:45:07 -05:00
call setline(line('.')+1, '')
call cursor(line('.')+1, col('.'))
2014-08-03 18:02:51 -04:00
endif
2015-12-08 08:20:04 -05:00
if self.getShowBookmarks()
2015-07-13 06:22:46 -04:00
call self._renderBookmarks()
2014-08-03 18:02:51 -04:00
endif
2018-02-04 06:35:08 -05:00
" add the 'up a dir' line
2015-12-08 08:20:04 -05:00
if !self.isMinimal()
2020-01-07 07:45:07 -05:00
call setline(line('.')+1, s:UI.UpDirLine())
call cursor(line('.')+1, col('.'))
2014-08-03 18:02:51 -04:00
endif
2018-02-04 06:35:08 -05:00
" draw the header line
2015-12-08 08:20:04 -05:00
let header = self.nerdtree.root.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
2020-01-07 07:45:07 -05:00
call setline(line('.')+1, header)
call cursor(line('.')+1, col('.'))
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" draw the tree
2017-03-07 12:04:28 -05:00
silent put =self.nerdtree.root.renderToString()
2014-08-03 18:02:51 -04:00
2018-02-04 06:35:08 -05:00
" delete the blank line at the top of the buffer
2014-08-03 18:02:51 -04:00
silent 1,1delete _
2018-02-04 06:35:08 -05:00
" restore the view
2014-08-03 18:02:51 -04:00
let old_scrolloff=&scrolloff
let &scrolloff=0
call cursor(topLine, 1)
normal! zt
call cursor(curLine, curCol)
let &scrolloff = old_scrolloff
2018-06-14 06:31:12 -04:00
setlocal readonly nomodifiable
2014-08-03 18:02:51 -04:00
endfunction
2018-02-04 06:35:08 -05:00
" 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
2014-08-03 18:02:51 -04:00
function! s:UI.renderViewSavingPosition()
let currentNode = g:NERDTreeFileNode.GetSelected()
2018-02-04 06:35:08 -05:00
" go up the tree till we find a node that will be visible or till we run
" out of nodes
2020-01-07 07:45:07 -05:00
while currentNode !=# {} && !currentNode.isVisible() && !currentNode.isRoot()
2014-08-03 18:02:51 -04:00
let currentNode = currentNode.parent
endwhile
2015-12-08 08:20:04 -05:00
call self.render()
2014-08-03 18:02:51 -04:00
2020-01-07 07:45:07 -05:00
if currentNode !=# {}
2014-08-03 18:02:51 -04:00
call currentNode.putCursorHere(0, 0)
endif
endfunction
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.toggleHelp() {{{1
2015-12-08 08:20:04 -05:00
function! s:UI.toggleHelp()
let self._showHelp = !self._showHelp
endfunction
2014-08-03 18:02:51 -04:00
" FUNCTION: s:UI.toggleIgnoreFilter() {{{1
" toggles the use of the NERDTreeIgnore option
function! s:UI.toggleIgnoreFilter()
2015-12-08 08:20:04 -05:00
let self._ignoreEnabled = !self._ignoreEnabled
call self.renderViewSavingPosition()
call self.centerView()
2014-08-03 18:02:51 -04:00
endfunction
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
2018-08-25 12:13:42 -04:00
" Toggle the visibility of the Bookmark table.
2014-08-03 18:02:51 -04:00
function! s:UI.toggleShowBookmarks()
2015-12-08 08:20:04 -05:00
let self._showBookmarks = !self._showBookmarks
2018-08-25 12:13:42 -04:00
2015-12-08 08:20:04 -05:00
if self.getShowBookmarks()
call self.nerdtree.render()
2015-07-13 06:22:46 -04:00
call g:NERDTree.CursorToBookmarkTable()
2014-08-03 18:02:51 -04:00
else
2018-08-25 12:13:42 -04:00
if empty(g:NERDTreeFileNode.GetSelected())
call b:NERDTree.root.putCursorHere(0, 0)
normal! 0
endif
2015-12-08 08:20:04 -05:00
call self.renderViewSavingPosition()
2014-08-03 18:02:51 -04:00
endif
2018-08-25 12:13:42 -04:00
2015-12-08 08:20:04 -05:00
call self.centerView()
2014-08-03 18:02:51 -04:00
endfunction
" FUNCTION: s:UI.toggleShowFiles() {{{1
" toggles the display of hidden files
function! s:UI.toggleShowFiles()
2015-12-08 08:20:04 -05:00
let self._showFiles = !self._showFiles
call self.renderViewSavingPosition()
call self.centerView()
2014-08-03 18:02:51 -04:00
endfunction
" FUNCTION: s:UI.toggleShowHidden() {{{1
" toggles the display of hidden files
function! s:UI.toggleShowHidden()
2015-12-08 08:20:04 -05:00
let self._showHidden = !self._showHidden
call self.renderViewSavingPosition()
2014-08-03 18:02:51 -04:00
call self.centerView()
endfunction
" FUNCTION: s:UI.toggleZoom() {{{1
" zoom (maximize/minimize) the NERDTree window
function! s:UI.toggleZoom()
2020-01-07 07:45:07 -05:00
if exists('b:NERDTreeZoomed') && b:NERDTreeZoomed
let size = exists('b:NERDTreeOldWindowSize') ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
call nerdtree#exec('silent vertical resize '. size, 1)
2014-08-03 18:02:51 -04:00
let b:NERDTreeZoomed = 0
else
2020-01-07 07:45:07 -05:00
call nerdtree#exec('vertical resize '. get(g:, 'NERDTreeWinSizeMax', ''), 1)
2014-08-03 18:02:51 -04:00
let b:NERDTreeZoomed = 1
endif
endfunction
2015-07-13 06:22:46 -04:00
2018-02-04 06:35:08 -05:00
" FUNCTION: s:UI.UpDirLine() {{{1
2015-07-13 06:22:46 -04:00
function! s:UI.UpDirLine()
return '.. (up a dir)'
endfunction
2018-02-04 06:35:08 -05:00
" vim: set sw=4 sts=4 et fdm=marker: