From 3601cef1377937f01347b20a8c6c303f5f429f51 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 27 Apr 2022 21:27:58 +0800 Subject: [PATCH] feat(mappings): do not replace existing mapping for simplified form --- runtime/doc/vim_diff.txt | 4 +++ src/nvim/getchar.c | 5 +++ test/functional/ui/input_spec.lua | 57 +++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 540043f52d..bada506c63 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -365,6 +365,10 @@ Macro/|recording| behavior macros and 'keymap' at the same time. This also means you can use |:imap| on the results of keys from 'keymap'. +Mappings: + Creating a mapping for a simplifiable key (e.g. ) doesn't replace an + existing mapping for its simplified form (e.g. ). + Motion: The |jumplist| avoids useless/phantom jumps. diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index a26ca3f2c8..58daa9631a 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3279,6 +3279,11 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T } else if (n != len) { // new entry is ambiguous mpp = &(mp->m_next); continue; + } else if (keyround1_simplified && !mp->m_simplified) { + // In keyround for simplified keys, don't replace + // a mapping without m_simplified flag. + did_it = true; + break; } else if (args->unique) { if (is_abbrev) { semsg(_("E226: abbreviation already exists for %s"), p); diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 25fc9cdcd1..0f4e97088c 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -173,11 +173,20 @@ describe('input pairs', function() eq('\t\t', curbuf_contents()) end) - it('can be mapped', function() - command('inoremap TAB!') - command('inoremap CTRL-I!') - feed('i') - eq('TAB!CTRL-I!', curbuf_contents()) + describe('can be mapped separately', function() + it('if is mapped after ', function() + command('inoremap CTRL-I!') + command('inoremap TAB!') + feed('i') + eq('TAB!CTRL-I!', curbuf_contents()) + end) + + it('if is mapped before ', function() + command('inoremap TAB!') + command('inoremap CTRL-I!') + feed('i') + eq('TAB!CTRL-I!', curbuf_contents()) + end) end) end) @@ -187,11 +196,20 @@ describe('input pairs', function() eq('unos\ndos\ntres', curbuf_contents()) end) - it('can be mapped', function() - command('inoremap SNIPPET!') - command('inoremap , and then') - feed('iunosdostres') - eq('unosSNIPPET!dos, and then\ntres', curbuf_contents()) + describe('can be mapped separately', function() + it('if is mapped after ', function() + command('inoremap SNIPPET!') + command('inoremap , and then') + feed('iunosdostres') + eq('unosSNIPPET!dos, and then\ntres', curbuf_contents()) + end) + + it('if is mapped before ', function() + command('inoremap , and then') + command('inoremap SNIPPET!') + feed('iunosdostres') + eq('unosSNIPPET!dos, and then\ntres', curbuf_contents()) + end) end) end) @@ -201,11 +219,20 @@ describe('input pairs', function() eq('doubledoublesingle', curbuf_contents()) end) - it('can be mapped', function() - command('inoremap HALLOJ!') - command('inoremap ,') - feed('2adubbelupp') - eq('dubbelHALLOJ!upp,dubbelHALLOJ!upp,', curbuf_contents()) + describe('can be mapped separately', function() + it('if is mapped after ', function() + command('inoremap HALLOJ!') + command('inoremap ,') + feed('2adubbelupp') + eq('dubbelHALLOJ!upp,dubbelHALLOJ!upp,', curbuf_contents()) + end) + + it('if is mapped before ', function() + command('inoremap ,') + command('inoremap HALLOJ!') + feed('2adubbelupp') + eq('dubbelHALLOJ!upp,dubbelHALLOJ!upp,', curbuf_contents()) + end) end) end) end)