mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-22 15:18:23 +08:00
Restore the default behavior of the <CR> key. (#1221)
* Restore <CR>'s default behavior to be the same as o's. * Remove the dictionary validation, and simplify initCustomOpenArgs(). There was a bug in the validation logic that caused a valid integer value of 'keepopen' to always be overwritten with the defaultOpenArgs' value. It was always comparing its type to the type of a string. I fixed this by removing all the type validation, and wrapping the code with a try-catch block. If NERDTreeCustomOpenArgs is not a dictionary, an error message will print and the defaults will be used instead. * Add fold markers to new functions. * Update version number in change log.
This commit is contained in:
parent
d3f9fc44ca
commit
3a9d533f3d
|
@ -5,6 +5,7 @@
|
||||||
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
|
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
|
||||||
-->
|
-->
|
||||||
#### 6.10
|
#### 6.10
|
||||||
|
- **.6**: Restore the default behavior of the <CR> 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)
|
- **.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)
|
- **.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)
|
- **.3**: Add new FAQ and answer: How to prevent buffers replacing NERDTree. (PhilRunninger) [#1215](https://github.com/preservim/nerdtree/pull/1215)
|
||||||
|
|
|
@ -30,12 +30,12 @@ endfunction
|
||||||
" SECTION: General Functions {{{1
|
" SECTION: General Functions {{{1
|
||||||
"============================================================
|
"============================================================
|
||||||
|
|
||||||
" FUNCTION: nerdtree#closeTreeOnOpen()
|
" FUNCTION: nerdtree#closeTreeOnOpen() {{{2
|
||||||
function! nerdtree#closeTreeOnOpen() abort
|
function! nerdtree#closeTreeOnOpen() abort
|
||||||
return g:NERDTreeQuitOnOpen == 1 || g:NERDTreeQuitOnOpen == 3
|
return g:NERDTreeQuitOnOpen == 1 || g:NERDTreeQuitOnOpen == 3
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: nerdtree#closeBookmarksOnOpen()
|
" FUNCTION: nerdtree#closeBookmarksOnOpen() {{{2
|
||||||
function! nerdtree#closeBookmarksOnOpen() abort
|
function! nerdtree#closeBookmarksOnOpen() abort
|
||||||
return g:NERDTreeQuitOnOpen == 2 || g:NERDTreeQuitOnOpen == 3
|
return g:NERDTreeQuitOnOpen == 2 || g:NERDTreeQuitOnOpen == 3
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
@ -109,40 +109,16 @@ endfunction
|
||||||
|
|
||||||
"FUNCTION: s:initCustomOpenArgs() {{{1
|
"FUNCTION: s:initCustomOpenArgs() {{{1
|
||||||
function! s:initCustomOpenArgs() abort
|
function! s:initCustomOpenArgs() abort
|
||||||
let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p'}, 'dir': {}}
|
let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p', 'keepopen':!nerdtree#closeTreeOnOpen()}, 'dir': {}}
|
||||||
let l:customOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})
|
try
|
||||||
|
let g:NERDTreeCustomOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})
|
||||||
if !s:validateType(l:customOpenArgs, type({})) || empty(l:customOpenArgs)
|
call extend(g:NERDTreeCustomOpenArgs, l:defaultOpenArgs, 'keep')
|
||||||
let g:NERDTreeCustomOpenArgs = l:customOpenArgs
|
catch /^Vim(\a\+):E712:/
|
||||||
return l:defaultOpenArgs
|
call nerdtree#echoWarning('g:NERDTreeCustomOpenArgs is not set properly. Using default value.')
|
||||||
endif
|
let g:NERDTreeCustomOpenArgs = l:defaultOpenArgs
|
||||||
|
finally
|
||||||
for l:typeKey in keys(l:defaultOpenArgs)
|
return g:NERDTreeCustomOpenArgs
|
||||||
if !s:validateType(get(l:customOpenArgs, l:typeKey, {}), type({}))
|
endtry
|
||||||
\ || !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
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: s:activateAll() {{{1
|
"FUNCTION: s:activateAll() {{{1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user