Merge pull request #450 from vtsang/master
Optimized NERDTree when opening a large directory
This commit is contained in:
commit
008b62f71c
@ -34,6 +34,17 @@ function! nerdtree#compareNodes(n1, n2)
|
|||||||
return a:n1.path.compareTo(a:n2.path)
|
return a:n1.path.compareTo(a:n2.path)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: nerdtree#compareNodesBySortKey(n1, n2) {{{2
|
||||||
|
function! nerdtree#compareNodesBySortKey(n1, n2)
|
||||||
|
if a:n1.path.getSortKey() < a:n2.path.getSortKey()
|
||||||
|
return -1
|
||||||
|
elseif a:n1.path.getSortKey() > a:n2.path.getSortKey()
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: nerdtree#deprecated(func, [msg]) {{{2
|
" FUNCTION: nerdtree#deprecated(func, [msg]) {{{2
|
||||||
" Issue a deprecation warning for a:func. If a second arg is given, use this
|
" Issue a deprecation warning for a:func. If a second arg is given, use this
|
||||||
" as the deprecation message
|
" as the deprecation message
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
"we need to use this number many times for sorting... so we calculate it only
|
"we need to use this number many times for sorting... so we calculate it only
|
||||||
"once here
|
"once here
|
||||||
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
||||||
|
" used in formating sortKey, e.g. '%04d'
|
||||||
|
let s:format = "%0" . float2nr(ceil(log10(len(g:NERDTreeSortOrder)))) . "d"
|
||||||
|
|
||||||
|
|
||||||
"CLASS: Path
|
"CLASS: Path
|
||||||
"============================================================
|
"============================================================
|
||||||
@ -361,6 +364,24 @@ function! s:Path.getSortOrderIndex()
|
|||||||
return s:NERDTreeSortStarIndex
|
return s:NERDTreeSortStarIndex
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: Path.getSortKey() {{{1
|
||||||
|
"returns a string used in compare function for sorting
|
||||||
|
function! s:Path.getSortKey()
|
||||||
|
if !exists("self.sortKey")
|
||||||
|
let path = self.getLastPathComponent(1)
|
||||||
|
if !g:NERDTreeSortHiddenFirst
|
||||||
|
let path = substitute(path, '^[._]', '', '')
|
||||||
|
endif
|
||||||
|
if !g:NERDTreeCaseSensitiveSort
|
||||||
|
let path = tolower(path)
|
||||||
|
endif
|
||||||
|
let self.sortKey = printf(s:format, self.getSortOrderIndex()) . path
|
||||||
|
endif
|
||||||
|
|
||||||
|
return self.sortKey
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
"FUNCTION: Path.isUnixHiddenFile() {{{1
|
"FUNCTION: Path.isUnixHiddenFile() {{{1
|
||||||
"check for unix hidden files
|
"check for unix hidden files
|
||||||
function! s:Path.isUnixHiddenFile()
|
function! s:Path.isUnixHiddenFile()
|
||||||
|
@ -246,8 +246,12 @@ function! s:TreeDirNode._initChildren(silent)
|
|||||||
"filter out the .. and . directories
|
"filter out the .. and . directories
|
||||||
"Note: we must match .. AND ../ cos sometimes the globpath returns
|
"Note: we must match .. AND ../ cos sometimes the globpath returns
|
||||||
"../ for path with strange chars (eg $)
|
"../ for path with strange chars (eg $)
|
||||||
if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$'
|
" if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$'
|
||||||
|
"
|
||||||
|
" Regular expression is too expensive. Use simply string comparison
|
||||||
|
" instead
|
||||||
|
if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." &&
|
||||||
|
\ i[len(i)-2:1] != "." && i[len(i)-1] != "."
|
||||||
"put the next file in a new node and attach it
|
"put the next file in a new node and attach it
|
||||||
try
|
try
|
||||||
let path = g:NERDTreePath.New(i)
|
let path = g:NERDTreePath.New(i)
|
||||||
@ -405,8 +409,12 @@ function! s:TreeDirNode.refresh()
|
|||||||
"filter out the .. and . directories
|
"filter out the .. and . directories
|
||||||
"Note: we must match .. AND ../ cos sometimes the globpath returns
|
"Note: we must match .. AND ../ cos sometimes the globpath returns
|
||||||
"../ for path with strange chars (eg $)
|
"../ for path with strange chars (eg $)
|
||||||
if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$'
|
"if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$'
|
||||||
|
|
||||||
|
" Regular expression is too expensive. Use simply string comparison
|
||||||
|
" instead
|
||||||
|
if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." &&
|
||||||
|
\ i[len(i)-2:1] != "." && i[len(i)-1] != "."
|
||||||
try
|
try
|
||||||
"create a new path and see if it exists in this nodes children
|
"create a new path and see if it exists in this nodes children
|
||||||
let path = g:NERDTreePath.New(i)
|
let path = g:NERDTreePath.New(i)
|
||||||
@ -504,7 +512,7 @@ endfunction
|
|||||||
"directory priority.
|
"directory priority.
|
||||||
"
|
"
|
||||||
function! s:TreeDirNode.sortChildren()
|
function! s:TreeDirNode.sortChildren()
|
||||||
let CompareFunc = function("nerdtree#compareNodes")
|
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
||||||
call sort(self.children, CompareFunc)
|
call sort(self.children, CompareFunc)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user