Fix missing key case, add BC type checking (#1206)

* Fix missing key case, add BC type checking

Resolves #1205

* Assign g:NERDTreeCustomOpenArgs also before quick return

* Fix syntax to be compatibile with Vim 7.3
This commit is contained in:
Tomasz N 2021-01-19 03:23:52 +01:00 committed by GitHub
parent a7eb011e47
commit 7099f638ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,24 +108,24 @@ function! s:customOpenBookmark(node) abort
endfunction
"FUNCTION: s:initCustomOpenArgs() {{{1
" Make sure NERDTreeCustomOpenArgs has needed keys
function! s:initCustomOpenArgs() abort
let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p'}, 'dir': {}}
let l:customOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})
return extend(l:customOpenArgs, l:defaultOpenArgs, 'keep')
if v:false is# s:validateType(l:customOpenArgs, v:t_dict)
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 v:false is# s:validateType(get(l:customOpenArgs, l:typeKey, {}), v:t_dict)
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), v:t_string)
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]
@ -138,7 +138,7 @@ function! s:initCustomOpenArgs() abort
endfunction
function! s:validateType(variable, type) abort
if type(a:variable) is# a:type
if type(a:variable) == a:type
return v:true
endif