diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-09-24 21:07:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-24 21:07:18 +0800 |
commit | 291a6496327e90056ea68085ad52ab74ca1df752 (patch) | |
tree | cfa99d8e02bec8155f1acea266788a0d656761ad | |
parent | db056de29ad2d57ee8e1ba841d969560f9bc6714 (diff) | |
download | rneovim-291a6496327e90056ea68085ad52ab74ca1df752.tar.gz rneovim-291a6496327e90056ea68085ad52ab74ca1df752.tar.bz2 rneovim-291a6496327e90056ea68085ad52ab74ca1df752.zip |
fix(mapset): remove existing abbreviation of same lhs (#20320)
-rw-r--r-- | src/nvim/mapping.c | 2 | ||||
-rw-r--r-- | test/functional/vimscript/map_functions_spec.lua | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index a10146c110..6267e1c875 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2199,7 +2199,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) MapArguments unmap_args = MAP_ARGUMENTS_INIT; set_maparg_lhs_rhs(lhs, strlen(lhs), "", 0, LUA_NOREF, 0, &unmap_args); unmap_args.buffer = buffer; - buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, false, curbuf); + buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, is_abbr, curbuf); xfree(unmap_args.rhs); xfree(unmap_args.orig_rhs); diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index 96b86d053e..ed1863754a 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -12,6 +12,7 @@ local meths = helpers.meths local nvim = helpers.nvim local source = helpers.source local command = helpers.command +local exec_capture = helpers.exec_capture local pcall_err = helpers.pcall_err describe('maparg()', function() @@ -178,8 +179,9 @@ describe('mapset()', function() 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")) + meths.set_keymap('n', 'lhs', 'rhs', {desc = 'MAP DESCRIPTION'}) + eq('\nn lhs rhs\n MAP DESCRIPTION', + helpers.exec_capture("nmap lhs")) funcs.mapset('n', false, mapargs) eq('\nn lhs rhs\n map description', helpers.exec_capture("nmap lhs")) @@ -198,6 +200,22 @@ describe('mapset()', function() expect('<<lt><') end) + it('replaces an abbreviation of the same lhs #20320', function() + command('inoreabbr foo bar') + eq('\ni foo * bar', exec_capture('iabbr foo')) + feed('ifoo ') + expect('bar ') + local mapargs = funcs.maparg('foo', 'i', true, true) + command('inoreabbr foo BAR') + eq('\ni foo * BAR', exec_capture('iabbr foo')) + feed('foo ') + expect('bar BAR ') + funcs.mapset('i', true, mapargs) + eq('\ni foo * bar', exec_capture('iabbr foo')) + feed('foo<Esc>') + expect('bar BAR bar') + end) + it('can restore Lua callback from the dict returned by maparg()', function() eq(0, exec_lua([[ GlobalCount = 0 |