From 172202b49aefcc96758ea95b164631261577c2e7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Dec 2022 10:26:13 +0800 Subject: [PATCH] fix(mappings): use all buckets in second round of unmap (cherry picked from commit 32b5afd768b8020e12f02e08f2097efda00fe732) --- src/nvim/mapping.c | 2 +- test/functional/ex_cmds/map_spec.lua | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 001bbf7e48..d140bd5220 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -685,7 +685,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, for (int round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1 && !did_it && !got_int; round++) { int hash_start, hash_end; - if (has_lhs || is_abbrev) { + if ((round == 0 && has_lhs) || is_abbrev) { // just use one hash hash_start = is_abbrev ? 0 : MAP_HASH(mode, lhs[0]); hash_end = hash_start + 1; diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index c6bdd017bd..f01193386c 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local exec = helpers.exec +local exec_capture = helpers.exec_capture local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear @@ -30,12 +31,12 @@ describe(':*map', function() expect('-foo-') end) - it('shows as mapping rhs', function() + it('shows as mapping rhs', function() command('nmap asdf ') eq([[ n asdf ]], - helpers.exec_capture('nmap asdf')) + exec_capture('nmap asdf')) end) it('mappings with description can be filtered', function() @@ -48,7 +49,7 @@ n asdf3 qwert do the other thing n asdf1 qwert do the one thing]], - helpers.exec_capture('filter the nmap')) + exec_capture('filter the nmap')) end) it(' mappings ignore nore', function() @@ -84,6 +85,12 @@ n asdf1 qwert eq(2, meths.eval('x')) eq('Some te', eval("getline('.')")) end) + + it(':unmap with rhs works when lhs is in another bucket #21530', function() + command('map F Foo') + command('unmap Foo') + eq('\nNo mapping found', exec_capture('map F')) + end) end) describe('Screen', function()