mirror of
https://github.com/preservim/nerdtree.git
synced 2024-10-18 13:50:21 +03:00
Make the behavior of window splits consistent (#1035)
* add option to spawn split from previous window * Update some comments and remove debugging statement. * Simplify the code, and make it respect NERDTreeWinPos and 'splitbelow'. * Better logic for getting NERDTree window number when not active window. * Use common functions for splitting windows. Make splitting respect user. The placement of split windows now respects the user's choices for the splitright and splitbelow settings, and the g:NERDTreeWinPos variable. * Update version number in change log.
This commit is contained in:
parent
9193962ad8
commit
bd744eab8d
@ -1,5 +1,7 @@
|
||||
# Change Log
|
||||
|
||||
#### 6.0...
|
||||
- **.0**: Make the behavior of window splits consistent [#1035](https://github.com/scrooloose/nerdtree/pull/1035)
|
||||
#### 5.3...
|
||||
- **.3**: Fix (p)ath not displaying in the minimal menu [#1038](https://github.com/scrooloose/nerdtree/pull/1038)
|
||||
- **.2**: Enable events when closing NerdTree window. [#1037](https://github.com/scrooloose/nerdtree/pull/1037)
|
||||
|
@ -4,6 +4,11 @@ endif
|
||||
let g:loaded_nerdtree_autoload = 1
|
||||
|
||||
let s:rootNERDTreePath = resolve(expand("<sfile>:p:h:h"))
|
||||
|
||||
"FUNCTION: nerdtree#version(...) {{{1
|
||||
" If any value is given as an argument, the entire line of text from the
|
||||
" change log is shown for the current version; otherwise, only the version
|
||||
" number is shown.
|
||||
function! nerdtree#version(...)
|
||||
let l:changelog = readfile(join([s:rootNERDTreePath, "CHANGELOG.md"], nerdtree#slash()))
|
||||
let l:text = 'Unknown'
|
||||
@ -22,6 +27,7 @@ endfunction
|
||||
" SECTION: General Functions {{{1
|
||||
"============================================================
|
||||
|
||||
"FUNCTION: nerdtree#slash() {{{2
|
||||
function! nerdtree#slash()
|
||||
|
||||
if nerdtree#runningWindows()
|
||||
@ -49,7 +55,6 @@ function! nerdtree#and(x,y)
|
||||
if (l:x % 2) && (l:y % 2)
|
||||
let l:result += float2nr(pow(2, l:n))
|
||||
endif
|
||||
echomsg l:x . ", " . l:y . " => " l:result
|
||||
let l:x = float2nr(l:x / 2)
|
||||
let l:y = float2nr(l:y / 2)
|
||||
let l:n += 1
|
||||
|
@ -148,12 +148,19 @@ function! s:NERDTree.GetWinNum()
|
||||
return bufwinnr(t:NERDTreeBufName)
|
||||
endif
|
||||
|
||||
" If WindowTree, there is no t:NERDTreeBufName variable. Search all windows.
|
||||
for w in range(1,winnr('$'))
|
||||
if bufname(winbufnr(w)) =~# '^' . g:NERDTreeCreator.BufNamePrefix() . '\d\+$'
|
||||
return w
|
||||
endif
|
||||
endfor
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.IsOpen() {{{1
|
||||
function! s:NERDTree.IsOpen()
|
||||
return s:NERDTree.GetWinNum() != -1 || bufname('%') =~# '^' . g:NERDTreeCreator.BufNamePrefix() . '\d\+$'
|
||||
return s:NERDTree.GetWinNum() != -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.isTabTree() {{{1
|
||||
|
@ -71,9 +71,9 @@ endfunction
|
||||
function! s:Opener._gotoTargetWin()
|
||||
if b:NERDTree.isWinTree()
|
||||
if self._where == 'v'
|
||||
vsplit
|
||||
call self._newVSplit()
|
||||
elseif self._where == 'h'
|
||||
split
|
||||
call self._newSplit()
|
||||
elseif self._where == 't'
|
||||
tabnew
|
||||
endif
|
||||
@ -153,44 +153,17 @@ endfunction
|
||||
|
||||
" FUNCTION: Opener._newSplit() {{{1
|
||||
function! s:Opener._newSplit()
|
||||
" Save the user's settings for splitbelow and splitright
|
||||
let savesplitbelow=&splitbelow
|
||||
let savesplitright=&splitright
|
||||
|
||||
" 'there' will be set to a command to move from the split window
|
||||
" back to the explorer window
|
||||
"
|
||||
" 'back' will be set to a command to move from the explorer window
|
||||
" back to the newly split window
|
||||
"
|
||||
" 'right' and 'below' will be set to the settings needed for
|
||||
" splitbelow and splitright IF the explorer is the only window.
|
||||
"
|
||||
let there= g:NERDTreeWinPos ==# "left" ? "wincmd h" : "wincmd l"
|
||||
let back = g:NERDTreeWinPos ==# "left" ? "wincmd l" : "wincmd h"
|
||||
let right= g:NERDTreeWinPos ==# "left"
|
||||
let below=0
|
||||
|
||||
" Attempt to go to adjacent window
|
||||
call nerdtree#exec(back, 1)
|
||||
|
||||
let onlyOneWin = (winnr("$") ==# 1)
|
||||
|
||||
" If no adjacent window, set splitright and splitbelow appropriately
|
||||
let savesplitright = &splitright
|
||||
if onlyOneWin
|
||||
let &splitright=right
|
||||
let &splitbelow=below
|
||||
else
|
||||
" found adjacent window - invert split direction
|
||||
let &splitright=!right
|
||||
let &splitbelow=!below
|
||||
let &splitright = (g:NERDTreeWinPos ==# "left")
|
||||
endif
|
||||
|
||||
let splitMode = onlyOneWin ? "vertical" : ""
|
||||
|
||||
" Open the new window
|
||||
try
|
||||
exec(splitMode." sp ")
|
||||
call nerdtree#exec('wincmd p', 1)
|
||||
" If only one window (ie. NERDTree), split vertically instead.
|
||||
call nerdtree#exec(onlyOneWin ? "vertical split" : "split",1)
|
||||
catch /^Vim\%((\a\+)\)\=:E37/
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
|
||||
@ -200,14 +173,12 @@ function! s:Opener._newSplit()
|
||||
|
||||
"resize the tree window if no other window was open before
|
||||
if onlyOneWin
|
||||
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
|
||||
call nerdtree#exec(there, 1)
|
||||
exec("silent ". splitMode ." resize ". size)
|
||||
let size = exists('b:NERDTreeOldWindowSize') ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
|
||||
call nerdtree#exec('wincmd p', 1)
|
||||
call nerdtree#exec('silent '. splitMode .' resize '. size, 1)
|
||||
call nerdtree#exec('wincmd p', 0)
|
||||
endif
|
||||
|
||||
" Restore splitmode settings
|
||||
let &splitbelow=savesplitbelow
|
||||
let &splitright=savesplitright
|
||||
endfunction
|
||||
|
||||
@ -215,7 +186,10 @@ endfunction
|
||||
function! s:Opener._newVSplit()
|
||||
let l:winwidth = winwidth('.')
|
||||
|
||||
if winnr('$') == 1
|
||||
let onlyOneWin = (winnr("$") ==# 1)
|
||||
let savesplitright = &splitright
|
||||
if onlyOneWin
|
||||
let &splitright = (g:NERDTreeWinPos ==# "left")
|
||||
let l:winwidth = g:NERDTreeWinSize
|
||||
endif
|
||||
|
||||
@ -229,6 +203,7 @@ function! s:Opener._newVSplit()
|
||||
execute 'silent vertical resize ' . l:winwidth
|
||||
|
||||
call nerdtree#exec(l:currentWindowNumber . 'wincmd w', 0)
|
||||
let &splitright=savesplitright
|
||||
endfunction
|
||||
|
||||
" FUNCTION: Opener.open(target) {{{1
|
||||
|
Loading…
Reference in New Issue
Block a user