mapset({mode}, {abbr}, {dict}) *mapset()*
mapset({dict})
Restore a mapping from a dictionary, possibly returned by
|maparg()| or |maplist()|. A buffer mapping, when dict.buffer
is true, is set on the current buffer; it is up to the caller
to ensure that the intended buffer is the current buffer. This
feature allows copying mappings from one buffer to another.
So since mapset() only restores mappings to the current buffer, previous mappings are not restored properly if the popup closes while the cursor is in another buffer. This can happen if e.g. switching to a different window while the popup is open or if the popup itself is focused and then closed with i.e. <C-w>q.
The fix is to temporarily set the current buffer by wrapping the call in vim.api.nvim_buf_call.
And then I also replaced the 0 and 1 arguments with false and true - luals was complaining about incorrect types.
From the vim docs for
mapset()
:So since
mapset()
only restores mappings to the current buffer, previous mappings are not restored properly if the popup closes while the cursor is in another buffer. This can happen if e.g. switching to a different window while the popup is open or if the popup itself is focused and then closed with i.e.<C-w>q
.The fix is to temporarily set the current buffer by wrapping the call in
vim.api.nvim_buf_call
.And then I also replaced the
0
and1
arguments withfalse
andtrue
- luals was complaining about incorrect types.