mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 20:08:17 +00:00
Merge pull request #18229 from zeertzjq/backport-18227-to-release-0.7
[Backport release-0.7] fix(lua): don't mutate opts parameter of vim.keymap.del (#18227)
This commit is contained in:
@@ -130,7 +130,6 @@ function keymap.del(modes, lhs, opts)
|
|||||||
local buffer = false
|
local buffer = false
|
||||||
if opts.buffer ~= nil then
|
if opts.buffer ~= nil then
|
||||||
buffer = opts.buffer == true and 0 or opts.buffer
|
buffer = opts.buffer == true and 0 or opts.buffer
|
||||||
opts.buffer = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if buffer == false then
|
if buffer == false then
|
||||||
|
@@ -2755,6 +2755,39 @@ describe('vim.keymap', function()
|
|||||||
eq('\nNo mapping found', helpers.exec_capture('nmap asdf'))
|
eq('\nNo mapping found', helpers.exec_capture('nmap asdf'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('works with buffer-local mappings', function()
|
||||||
|
eq(0, exec_lua [[
|
||||||
|
GlobalCount = 0
|
||||||
|
vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end, {buffer=true})
|
||||||
|
return GlobalCount
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('asdf\n')
|
||||||
|
|
||||||
|
eq(1, exec_lua[[return GlobalCount]])
|
||||||
|
|
||||||
|
exec_lua [[
|
||||||
|
vim.keymap.del('n', 'asdf', {buffer=true})
|
||||||
|
]]
|
||||||
|
|
||||||
|
feed('asdf\n')
|
||||||
|
|
||||||
|
eq(1, exec_lua[[return GlobalCount]])
|
||||||
|
eq('\nNo mapping found', helpers.exec_capture('nmap asdf'))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('does not mutate the opts parameter', function()
|
||||||
|
eq(true, exec_lua [[
|
||||||
|
opts = {buffer=true}
|
||||||
|
vim.keymap.set('n', 'asdf', function() end, opts)
|
||||||
|
return opts.buffer
|
||||||
|
]])
|
||||||
|
eq(true, exec_lua [[
|
||||||
|
vim.keymap.del('n', 'asdf', opts)
|
||||||
|
return opts.buffer
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('can do <Plug> mappings', function()
|
it('can do <Plug> mappings', function()
|
||||||
eq(0, exec_lua [[
|
eq(0, exec_lua [[
|
||||||
GlobalCount = 0
|
GlobalCount = 0
|
||||||
|
Reference in New Issue
Block a user