Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keycode merge bugs introduced with 9875baef #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions autoload/which_key.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ let g:which_key#TYPE = s:TYPE
let s:should_note_winid = exists('*win_getid')

function! which_key#register(prefix, dict, ...) abort
let key = has_key(s:MERGE_INTO, a:prefix) ?
\ s:MERGE_INTO[a:prefix] : a:prefix
let key = has_key(s:KEYCODES, a:prefix) ?
\ s:KEYCODES[a:prefix] : a:prefix
let key = has_key(s:MERGE_INTO, key) ?
\ s:MERGE_INTO[key] : key
let val = a:dict
if a:0 == 1
call extend(s:desc[a:1], {key:val})
Expand All @@ -53,10 +55,13 @@ function! s:handle_char_on_start_is_ok(c) abort
if which_key#char_handler#is_exit_code(a:c)
return 1
endif
let char = type(a:c) == s:TYPE.number ? nr2char(a:c) : a:c
let char = which_key#char_handler#parse_raw(a:c)
if has_key(s:KEYCODES, char)
let char = s:KEYCODES[char]
endif
if has_key(s:MERGE_INTO, char)
let char = s:MERGE_INTO[char]
endif
let s:which_key_trigger .= ' '.(char ==# ' ' ? '<Space>' : char)
let next_level = get(s:runtime, char)
let ty = type(next_level)
Expand Down Expand Up @@ -148,7 +153,7 @@ function! s:create_runtime(mode, key)
if type(s:desc[mode][key]) == s:TYPE.dict
let runtime = deepcopy(s:desc[mode][key])
else
let runtime = deepcopy({s:desc[mode][key]})
let runtime = deepcopy(eval(s:desc[mode][key]))
endif
let native = s:cache[mode][key]
call s:merge(runtime, native)
Expand All @@ -162,12 +167,12 @@ function! s:merge(target, native) " {{{
let target = a:target
let native = a:native
" e.g. <C-І> is merged into <Tab>, '<Space>' is merged into ' '
call map(target, {k,v ->
\ has_key(s:MERGE_INTO, k) ?
\ (has_key(target, s:MERGE_INTO[k]) ?
\ extend(target[s:MERGE_INTO[k]], target[k], 'keep') :
\ extend(target, {s:MERGE_INTO[k]: target[k]})) :
\ v})
let mergekeys = filter(copy(target), {k,_ -> has_key(s:MERGE_INTO, k)})
call map(mergekeys, {k,v ->
\ (has_key(target, s:MERGE_INTO[k]) ?
\ extend(target[s:MERGE_INTO[k]], target[k], 'keep') :
\ extend(target, {s:MERGE_INTO[k]: target[k]}))
\ })
call filter(target, {k,_ -> !has_key(s:MERGE_INTO, k)})
for [k, V] in items(target)
" Support a `Dictionary-function` for on-the-fly mappings
Expand Down