mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
feat(mapset): support restoring "replace_keycodes" and "desc"
This commit is contained in:
@@ -428,6 +428,9 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @param args "rhs", "rhs_lua", "orig_rhs", "expr", "silent", "nowait", "replace_keycodes" and
|
||||
/// and "desc" fields are used.
|
||||
/// "rhs", "rhs_lua", "orig_rhs" fields are cleared if "simplified" is false.
|
||||
/// @param sid -1 to use current_sctx
|
||||
static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char_u *keys,
|
||||
MapArguments *args, int noremap, int mode, bool is_abbr, scid_T sid,
|
||||
@@ -2162,15 +2165,15 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
if (tv_dict_get_number(d, "script") != 0) {
|
||||
noremap = REMAP_SCRIPT;
|
||||
}
|
||||
|
||||
// TODO: support "callback" and "desc"
|
||||
MapArguments args = {
|
||||
MapArguments args = { // TODO(zeertzjq): support restoring "callback"?
|
||||
.rhs = (char_u *)rhs,
|
||||
.rhs_lua = LUA_NOREF,
|
||||
.orig_rhs = vim_strsave((char_u *)orig_rhs),
|
||||
.expr = tv_dict_get_number(d, "expr") != 0,
|
||||
.silent = tv_dict_get_number(d, "silent") != 0,
|
||||
.nowait = tv_dict_get_number(d, "nowait") != 0,
|
||||
.replace_keycodes = tv_dict_get_number(d, "replace_keycodes") != 0,
|
||||
.desc = tv_dict_get_string(d, "desc", false),
|
||||
};
|
||||
scid_T sid = (scid_T)tv_dict_get_number(d, "sid");
|
||||
linenr_T lnum = (linenr_T)tv_dict_get_number(d, "lnum");
|
||||
|
@@ -3,7 +3,10 @@ local helpers = require('test.functional.helpers')(after_each)
|
||||
local clear = helpers.clear
|
||||
local eq = helpers.eq
|
||||
local eval = helpers.eval
|
||||
local expect = helpers.expect
|
||||
local feed = helpers.feed
|
||||
local funcs = helpers.funcs
|
||||
local meths = helpers.meths
|
||||
local nvim = helpers.nvim
|
||||
local source = helpers.source
|
||||
local command = helpers.command
|
||||
@@ -163,3 +166,32 @@ describe('maparg()', function()
|
||||
eq(acmap('e`', 'f`'), funcs.maparg(ac('e`'), 'n', 0, 1))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('mapset()', function()
|
||||
before_each(clear)
|
||||
|
||||
it('can restore mapping description from the dict returned by maparg()', function()
|
||||
meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'})
|
||||
eq('\nn lhs rhs\n map description',
|
||||
helpers.exec_capture("nmap lhs"))
|
||||
local mapargs = funcs.maparg('lhs', 'n', false, true)
|
||||
meths.del_keymap('n', 'lhs')
|
||||
eq('\nNo mapping found', helpers.exec_capture("nmap lhs"))
|
||||
funcs.mapset('n', false, mapargs)
|
||||
eq('\nn lhs rhs\n map description',
|
||||
helpers.exec_capture("nmap lhs"))
|
||||
end)
|
||||
|
||||
it('can restore "replace_keycodes" from the dict returned by maparg()', function()
|
||||
meths.set_keymap('i', 'foo', [['<l' .. 't>']], {expr = true, replace_keycodes = true})
|
||||
feed('Afoo')
|
||||
expect('<')
|
||||
local mapargs = funcs.maparg('foo', 'i', false, true)
|
||||
meths.set_keymap('i', 'foo', [['<l' .. 't>']], {expr = true})
|
||||
feed('foo')
|
||||
expect('<<lt>')
|
||||
funcs.mapset('i', false, mapargs)
|
||||
feed('foo')
|
||||
expect('<<lt><')
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user