diff --git a/CHANGELOG.md b/CHANGELOG.md index 070b78a..8b84bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) --> #### 6.10 +- **.6**: Restore the default behavior of the key. (PhilRunninger) [#1221](https://github.com/preservim/nerdtree/pull/1221) - **.5**: Fix `{'keepopen':0}` in NERDTreeCustomOpenArgs (PhilRunninger) [#1217](https://github.com/preservim/nerdtree/pull/1217) - **.4**: Removed directory separator from sort key (Daniel E) [#1219](https://github.com/preservim/nerdtree/pull/1219) - **.3**: Add new FAQ and answer: How to prevent buffers replacing NERDTree. (PhilRunninger) [#1215](https://github.com/preservim/nerdtree/pull/1215) diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index 223f2f4..e6f687a 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -30,12 +30,12 @@ endfunction " SECTION: General Functions {{{1 "============================================================ -" FUNCTION: nerdtree#closeTreeOnOpen() +" FUNCTION: nerdtree#closeTreeOnOpen() {{{2 function! nerdtree#closeTreeOnOpen() abort return g:NERDTreeQuitOnOpen == 1 || g:NERDTreeQuitOnOpen == 3 endfunction -" FUNCTION: nerdtree#closeBookmarksOnOpen() +" FUNCTION: nerdtree#closeBookmarksOnOpen() {{{2 function! nerdtree#closeBookmarksOnOpen() abort return g:NERDTreeQuitOnOpen == 2 || g:NERDTreeQuitOnOpen == 3 endfunction diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 2cf6f45..1231e5e 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -109,40 +109,16 @@ endfunction "FUNCTION: s:initCustomOpenArgs() {{{1 function! s:initCustomOpenArgs() abort - let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p'}, 'dir': {}} - let l:customOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {}) - - if !s:validateType(l:customOpenArgs, type({})) || empty(l:customOpenArgs) - let g:NERDTreeCustomOpenArgs = l:customOpenArgs - return l:defaultOpenArgs - endif - - for l:typeKey in keys(l:defaultOpenArgs) - if !s:validateType(get(l:customOpenArgs, l:typeKey, {}), type({})) - \ || !has_key(l:customOpenArgs, l:typeKey) - let l:customOpenArgs[l:typeKey] = l:defaultOpenArgs[l:typeKey] - continue - endif - - for l:optionName in keys(l:defaultOpenArgs[l:typeKey]) - if s:validateType(get(l:customOpenArgs[l:typeKey], l:optionName, v:null), type('')) - continue - endif - let l:customOpenArgs[l:typeKey][l:optionName] = l:defaultOpenArgs[l:typeKey][l:optionName] - endfor - endfor - - let g:NERDTreeCustomOpenArgs = l:customOpenArgs - - return extend(l:customOpenArgs, l:defaultOpenArgs, 'keep') -endfunction - -function! s:validateType(variable, type) abort - if type(a:variable) == a:type - return v:true - endif - - return v:false + let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p', 'keepopen':!nerdtree#closeTreeOnOpen()}, 'dir': {}} + try + let g:NERDTreeCustomOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {}) + call extend(g:NERDTreeCustomOpenArgs, l:defaultOpenArgs, 'keep') + catch /^Vim(\a\+):E712:/ + call nerdtree#echoWarning('g:NERDTreeCustomOpenArgs is not set properly. Using default value.') + let g:NERDTreeCustomOpenArgs = l:defaultOpenArgs + finally + return g:NERDTreeCustomOpenArgs + endtry endfunction "FUNCTION: s:activateAll() {{{1