fix(api): add lhs option for keymap deletion

This commit is contained in:
Barrett Ruth
2026-07-25 10:26:01 -07:00
parent 1facf1e081
commit 22d44ef875
13 changed files with 120 additions and 31 deletions

View File

@@ -594,6 +594,39 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq('Invalid (empty) LHS', pcall_err(api.nvim_del_keymap, '', ''))
end)
it('del_keymap preserves {rhs} fallback by default #30258', function()
api.nvim_set_keymap('n', 'ge', 'q', {})
api.nvim_del_keymap('n', 'q')
eq({}, get_mapargs('n', 'ge'))
end)
it('del_keymap with opts.lhs matches only {lhs}, never {rhs} #30258', function()
api.nvim_set_keymap('n', 'ge', 'q', {})
eq('E31: No such mapping', pcall_err(api.nvim_del_keymap, 'n', 'q', { lhs = true }))
eq(generate_mapargs('n', 'ge', 'q'), get_mapargs('n', 'ge'))
api.nvim_del_keymap('n', 'ge', { lhs = true })
eq({}, get_mapargs('n', 'ge'))
end)
it('del_keymap for abbreviations with opts.lhs matches only {lhs}, never {rhs} #30258', function()
api.nvim_set_keymap('ia', 'foo', 'bar', {})
eq('E31: No such mapping', pcall_err(api.nvim_del_keymap, 'ia', 'bar', { lhs = true }))
eq(generate_mapargs('ia', 'foo', 'bar'), get_mapargs('ia', 'foo'))
api.nvim_del_keymap('ia', 'foo', { lhs = true })
eq({}, get_mapargs('ia', 'foo'))
end)
it('buf_del_keymap with opts.lhs matches only {lhs}, never {rhs} #30258', function()
api.nvim_buf_set_keymap(0, 'n', 'ge', 'q', {})
eq('E31: No such mapping', pcall_err(api.nvim_buf_del_keymap, 0, 'n', 'q', { lhs = true }))
eq(generate_mapargs('n', 'ge', 'q', { buffer = 1 }), get_mapargs('n', 'ge'))
api.nvim_buf_del_keymap(0, 'n', 'ge', { lhs = true })
eq({}, get_mapargs('n', 'ge'))
end)
it('error if LHS longer than MAXMAPLEN', function()
-- assume MAXMAPLEN of 50 chars, as declared in mapping_defs.h
local MAXMAPLEN = 50