mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-11 04:43:49 -05:00
rename and fix s:windowIsUsable()
This commit is contained in:
@@ -2230,6 +2230,37 @@ endfunction
|
|||||||
function! s:isTreeOpen()
|
function! s:isTreeOpen()
|
||||||
return s:getTreeWinNum() != -1
|
return s:getTreeWinNum() != -1
|
||||||
endfunction
|
endfunction
|
||||||
|
"FUNCTION: s:isWindowUsable(winnumber) {{{2
|
||||||
|
"Returns 1 if opening a file from the tree in the given window requires it to
|
||||||
|
"be split
|
||||||
|
"
|
||||||
|
"Args:
|
||||||
|
"winnumber: the number of the window in question
|
||||||
|
function! s:isWindowUsable(winnumber)
|
||||||
|
"gotta split if theres only one window (i.e. the NERD tree)
|
||||||
|
if winnr("$") == 1
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let oldwinnr = winnr()
|
||||||
|
exec a:winnumber . "wincmd p"
|
||||||
|
let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow')
|
||||||
|
let modified = &modified
|
||||||
|
exec oldwinnr . "wincmd p"
|
||||||
|
|
||||||
|
"if its a special window e.g. quickfix or another explorer plugin then we
|
||||||
|
"have to split
|
||||||
|
if specialWindow
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
if &hidden
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
return !modified || s:bufInWindows(winbufnr(a:winnumber)) >= 2
|
||||||
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: s:jumpToChild(direction) {{{2
|
" FUNCTION: s:jumpToChild(direction) {{{2
|
||||||
" Args:
|
" Args:
|
||||||
" direction: 0 if going to first child, 1 if going to last
|
" direction: 0 if going to first child, 1 if going to last
|
||||||
@@ -2300,11 +2331,11 @@ function! s:openFileNode(treenode)
|
|||||||
exec winnr . "wincmd w"
|
exec winnr . "wincmd w"
|
||||||
|
|
||||||
else
|
else
|
||||||
if s:windowIsUsable(winnr("#")) && s:firstNormalWindow() == -1
|
if !s:isWindowUsable(winnr("#")) && s:firstNormalWindow() == -1
|
||||||
call s:openFileNodeSplit(a:treenode)
|
call s:openFileNodeSplit(a:treenode)
|
||||||
else
|
else
|
||||||
try
|
try
|
||||||
if s:windowIsUsable(winnr("#"))
|
if !s:isWindowUsable(winnr("#"))
|
||||||
exec s:firstNormalWindow() . "wincmd w"
|
exec s:firstNormalWindow() . "wincmd w"
|
||||||
else
|
else
|
||||||
wincmd p
|
wincmd p
|
||||||
@@ -2767,37 +2798,6 @@ function! s:toggle(dir)
|
|||||||
call s:initNerdTree(a:dir)
|
call s:initNerdTree(a:dir)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
"FUNCTION: s:windowIsUsable() {{{2
|
|
||||||
"Returns 1 if opening a file from the tree in the given window requires it to
|
|
||||||
"be split
|
|
||||||
"
|
|
||||||
"Args:
|
|
||||||
"winnumber: the number of the window in question
|
|
||||||
function! s:windowIsUsable(winnumber)
|
|
||||||
"gotta split if theres only one window (i.e. the NERD tree)
|
|
||||||
if winnr("$") == 1
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
let oldwinnr = winnr()
|
|
||||||
exec a:winnumber . "wincmd p"
|
|
||||||
let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow')
|
|
||||||
let modified = &modified
|
|
||||||
exec oldwinnr . "wincmd p"
|
|
||||||
|
|
||||||
"if its a special window e.g. quickfix or another explorer plugin then we
|
|
||||||
"have to split
|
|
||||||
if specialWindow
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
if &hidden
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
return modified && s:bufInWindows(winbufnr(a:winnumber)) < 2
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
"SECTION: Interface bindings {{{1
|
"SECTION: Interface bindings {{{1
|
||||||
"============================================================
|
"============================================================
|
||||||
"FUNCTION: s:activateNode(forceKeepWindowOpen) {{{2
|
"FUNCTION: s:activateNode(forceKeepWindowOpen) {{{2
|
||||||
|
|||||||
Reference in New Issue
Block a user