mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-22 14:10:07 +08:00
move some rendering and cursor moving functions out of autoload
This commit is contained in:
parent
b0114d202b
commit
8b189cb263
|
@ -128,96 +128,9 @@ function! nerdtree#echoWarning(msg)
|
|||
echohl normal
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#putCursorOnBookmarkTable(){{{2
|
||||
"Places the cursor at the top of the bookmarks table
|
||||
function! nerdtree#putCursorOnBookmarkTable()
|
||||
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: nerdtree#putCursorInTreeWin(){{{2
|
||||
"Places the cursor in the nerd tree window
|
||||
function! nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.MustBeOpen()
|
||||
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#renderBookmarks {{{2
|
||||
function! nerdtree#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: nerdtree#renderView {{{2
|
||||
function! nerdtree#renderView()
|
||||
call b:NERDTree.render()
|
||||
endfunction
|
||||
"
|
||||
"FUNCTION: nerdtree#stripMarkupFromLine(line, removeLeadingSpaces){{{2
|
||||
"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! nerdtree#stripMarkupFromLine(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
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
||||
|
|
|
@ -278,7 +278,7 @@ function! s:findAndRevealPath()
|
|||
if !g:NERDTree.IsOpen()
|
||||
call g:NERDTreeCreator.TogglePrimary('')
|
||||
else
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
endif
|
||||
let b:NERDTreeShowHidden = g:NERDTreeShowHidden
|
||||
call s:chRoot(g:NERDTreeDirNode.New(p.getParent()))
|
||||
|
@ -288,7 +288,7 @@ function! s:findAndRevealPath()
|
|||
endif
|
||||
endif
|
||||
endif
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
call b:NERDTreeRoot.reveal(p)
|
||||
|
||||
if p.isUnixHiddenFile()
|
||||
|
|
|
@ -35,6 +35,36 @@ function! s:NERDTree.CloseIfQuitOnOpen()
|
|||
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()
|
||||
|
|
|
@ -189,7 +189,7 @@ function! s:Opener._newSplit()
|
|||
try
|
||||
exec(splitMode." sp ")
|
||||
catch /^Vim\%((\a\+)\)\=:E37/
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
|
||||
catch /^Vim\%((\a\+)\)\=:/
|
||||
"do nothing
|
||||
|
@ -219,7 +219,7 @@ function! s:Opener._newVSplit()
|
|||
vnew
|
||||
|
||||
"resize the nerd tree back to the original size
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
exec("silent vertical resize ". winwidth)
|
||||
call nerdtree#exec('wincmd p')
|
||||
endfunction
|
||||
|
@ -288,7 +288,7 @@ function! s:Opener._previousWindow()
|
|||
call nerdtree#exec('wincmd p')
|
||||
endif
|
||||
catch /^Vim\%((\a\+)\)\=:E37/
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
|
||||
catch /^Vim\%((\a\+)\)\=:/
|
||||
echo v:exception
|
||||
|
|
|
@ -171,7 +171,7 @@ function! s:UI.getPath(ln)
|
|||
let indent = self._indentLevelFor(line)
|
||||
|
||||
"remove the tree parts and the leading space
|
||||
let curFile = nerdtree#stripMarkupFromLine(line, 0)
|
||||
let curFile = self._stripMarkup(line, 0)
|
||||
|
||||
let wasdir = 0
|
||||
if curFile =~# '/$'
|
||||
|
@ -184,7 +184,7 @@ function! s:UI.getPath(ln)
|
|||
while lnum > 0
|
||||
let lnum = lnum - 1
|
||||
let curLine = getline(lnum)
|
||||
let curLineStripped = nerdtree#stripMarkupFromLine(curLine, 1)
|
||||
let curLineStripped = self._stripMarkup(curLine, 1)
|
||||
|
||||
"have we reached the top of the tree?
|
||||
if lnum == rootLine
|
||||
|
@ -235,7 +235,7 @@ function! s:UI.getLineNum(file_node)
|
|||
|
||||
let indent = self._indentLevelFor(curLine)
|
||||
if indent ==# curPathComponent
|
||||
let curLine = nerdtree#stripMarkupFromLine(curLine, 1)
|
||||
let curLine = self._stripMarkup(curLine, 1)
|
||||
|
||||
let curPath = join(pathcomponents, '/') . '/' . curLine
|
||||
if stridx(fullpath, curPath, 0) ==# 0
|
||||
|
@ -289,6 +289,23 @@ function! s:UI.MarkupReg()
|
|||
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
|
||||
|
@ -315,7 +332,7 @@ endfunction
|
|||
function! s:UI.saveScreenState()
|
||||
let win = winnr()
|
||||
try
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
let self._screenState = {}
|
||||
let self._screenState['oldPos'] = getpos(".")
|
||||
let self._screenState['oldTopLine'] = line("w0")
|
||||
|
@ -325,6 +342,46 @@ function! s:UI.saveScreenState()
|
|||
endtry
|
||||
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
|
||||
|
@ -347,7 +404,7 @@ function! s:UI.render()
|
|||
endif
|
||||
|
||||
if b:NERDTreeShowBookmarks
|
||||
call nerdtree#renderBookmarks()
|
||||
call self._renderBookmarks()
|
||||
endif
|
||||
|
||||
"add the 'up a dir' line
|
||||
|
@ -415,7 +472,7 @@ function! s:UI.toggleShowBookmarks()
|
|||
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
|
||||
if b:NERDTreeShowBookmarks
|
||||
call b:NERDTree.render()
|
||||
call nerdtree#putCursorOnBookmarkTable()
|
||||
call g:NERDTree.CursorToBookmarkTable()
|
||||
else
|
||||
call b:NERDTree.ui.renderViewSavingPosition()
|
||||
endif
|
||||
|
|
|
@ -186,7 +186,7 @@ endfunction
|
|||
|
||||
function! NERDTreeFocus()
|
||||
if g:NERDTree.IsOpen()
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
else
|
||||
call g:NERDTreeCreator.TogglePrimary("")
|
||||
endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user