Respect NERDTreeCustomOpenArgs when opening bookmark (#1200)

* Respect NERDTreeCustomOpenArgs when opening bookmark

* Update CHANGELOG

* Do not duplicate s:initCustomOpenArgs()

* Restore missing assignment

* fixup! Restore missing assignment

* fixup! Do not duplicate s:initCustomOpenArgs()

* Simplify loop iteration
This commit is contained in:
Tomasz N 2021-01-18 02:00:17 +01:00 committed by GitHub
parent aaa946fb6b
commit 7e1713853a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View File

@ -5,6 +5,7 @@
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
-->
#### 6.9
- **.12**: Respect NERDTreeCustomOpenArgs when opening bookmark (przepompownia) [#1200](https://github.com/preservim/nerdtree/pull/1200)
- **.11**: Revamp the README. (buncis, PhilRunninger) [#1192](https://github.com/preservim/nerdtree/pull/1192), [#1193](https://github.com/preservim/nerdtree/pull/1193)
- **.10**: Open a mirrored NERDTree with correct width (PhilRunninger) [#1177](https://github.com/preservim/nerdtree/pull/1177)
- **.9**: Updated Readme, removed typo (H3RSKO) [#1167](https://github.com/preservim/nerdtree/pull/1167)

View File

@ -110,8 +110,38 @@ endfunction
"FUNCTION: s:initCustomOpenArgs() {{{1
" Make sure NERDTreeCustomOpenArgs has needed keys
function! s:initCustomOpenArgs() abort
let g:NERDTreeCustomOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})
return extend(g:NERDTreeCustomOpenArgs, {'file':{'reuse': 'all', 'where': 'p'}, 'dir':{}}, 'keep')
let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p'}, 'dir': {}}
let l:customOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})
if v:false is# s:validateType(l:customOpenArgs, v:t_dict)
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)
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)
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) is# a:type
return v:true
endif
return v:false
endfunction
"FUNCTION: s:activateAll() {{{1
@ -500,9 +530,10 @@ function! nerdtree#ui_glue#openBookmark(name) abort
endtry
if l:bookmark.path.isDirectory
call l:bookmark.open(b:NERDTree)
else
call l:bookmark.open(b:NERDTree, {'where': 'p'})
return
endif
call l:bookmark.open(b:NERDTree, s:initCustomOpenArgs().file)
endfunction
" FUNCTION: s:openHSplit(target) {{{1