Skip to content

Commit

Permalink
Fix missing key case, add BC type checking (#1206)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
przepompownia authored Jan 19, 2021
1 parent a7eb011 commit 7099f63
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down

0 comments on commit 7099f63

Please sign in to comment.