Closed mmrwoods closed 1 year ago
cc @rene-descartes2021, it looks like this bug was introduced in one of your commits. Restoring some deleted conditional code fixes this bug, but I don't know if it will break something else. Maybe you can confirm this fix?
Applying the following patch fixes the issue with cached buffer local mappings, but I don't know if it will break something else...
index bc96b91..a5c0c97 100644
--- a/autoload/which_key.vim
+++ b/autoload/which_key.vim
@@ -141,6 +141,9 @@ function! s:cache_key(mode, key)
let mode = a:mode
let key = a:key
if !has_key(s:cache[mode], key) || g:which_key_run_map_on_popup
+ if key !=? '<C-I>'
+ let s:cache[mode][key] = {}
+ endif
call which_key#mappings#parse(key, s:cache[mode], mode)
endif
endfunction
After updating
vim-which-key
recently I've noticed that buffer local mappings seem to be cached even withlet g:which_key_run_map_on_popup = 1
in my vimrc.Environment (please complete the following information):
Describe the bug With g:which_key_run_map_on_popup set to 1, if I create a buffer local mapping and load the which key menu, e.g.
:WhichKey ','
, my buffer local mapping is shown as expected. If I then open another buffer which does not have this mapping and again load the which key menu the buffer local mapping I added for the previous buffer is still shown.To Reproduce
min.vim
:foo.md
andfoo.vim
files, e.g.echo foo > foo.md
,echo foo > foo.vim
vim -u min.vim
,
and you will see the \:edit foo.md<cr>
followed by,
and you will see both the \:verbose nmap<cr>
and note that you can see the \:edit foo.vim<cr>
followed by,
and you will still see both the \:verbose map<cr>
and note there is no \Expected behavior When g:which_key_run_map_on_popup is set to 1, the which key menu items should not be cached and buffer local mappings should only appear in the menu when editing the relevant buffer.
Screenshots Which key menu after opening vim without editing a file.
Which key menu after opening a markdown file (buffer local mapping)
Which key menu after opening a non-markdown file (no buffer local mapping)
Additional context
git bisect
tells me this bug was introduced in commit 654dfc15, but I have not investigated further (if I find some time I'll try to track down the root cause and fix it in a PR).