diff options
author | Shadman <13149513+shadmansaleh@users.noreply.github.com> | 2022-02-16 14:39:50 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 16:39:50 +0800 |
commit | 9a74c2b04ac8f54a17925a437b5a2f03b18f6281 (patch) | |
tree | 7d2dc0766e3c7e99646a9db56f8f505fb579f27e | |
parent | deb33a9775f53d2b32aeeb1825e773bccb039ca4 (diff) | |
download | rneovim-9a74c2b04ac8f54a17925a437b5a2f03b18f6281.tar.gz rneovim-9a74c2b04ac8f54a17925a437b5a2f03b18f6281.tar.bz2 rneovim-9a74c2b04ac8f54a17925a437b5a2f03b18f6281.zip |
feat(mappings): considering map description when filtering (#17423)
-rw-r--r-- | runtime/doc/map.txt | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 4 | ||||
-rw-r--r-- | test/functional/api/keymap_spec.lua | 23 |
3 files changed, 21 insertions, 8 deletions
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 2d2795b1ca..89df42600c 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -502,7 +502,7 @@ Note: When using mappings for Visual mode, you can use the "'<" mark, which is the start of the last selected Visual area in the current buffer |'<|. The |:filter| command can be used to select what mappings to list. The -pattern is matched against the {lhs} and {rhs} in the raw form. +pattern is matched against the {lhs}, {rhs} and {desc} in the raw form. *:map-verbose* When 'verbose' is non-zero, listing a key map will also display where it was diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index cc653bb4e9..470bf56a6e 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3433,8 +3433,8 @@ static void showmap(mapblock_T *mp, bool local) { size_t len = 1; - if (message_filtered(mp->m_keys) - && mp->m_str != NULL && message_filtered(mp->m_str)) { + if (message_filtered(mp->m_keys) && message_filtered(mp->m_str) + && (mp->m_desc == NULL || message_filtered((char_u *)mp->m_desc))) { return; } diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 06b699193a..e49e0b8cc4 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -877,6 +877,24 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq("\nn lhs rhs\n map description", helpers.exec_capture("nmap lhs")) end) + + it ('can :filter maps based on description', function() + meths.set_keymap('n', 'asdf1', 'qwert', {desc='do the one thing'}) + meths.set_keymap('n', 'asdf2', 'qwert', {desc='doesnot really do anything'}) + meths.set_keymap('n', 'asdf3', 'qwert', {desc='do the other thing'}) + eq([[ + +n asdf3 qwert + do the other thing +n asdf1 qwert + do the one thing]], + helpers.exec_capture('filter the nmap')) + end) + + it ('shows <nop> as map rhs', function() + meths.set_keymap('n', 'asdf', '<nop>', {}) + eq('\nn asdf <Nop>', helpers.exec_capture('nmap asdf')) + end) end) describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() @@ -1037,9 +1055,4 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) - - it ('shows <nop> as map rhs', function() - meths.set_keymap('n', 'asdf', '<nop>', {}) - eq('\nn asdf <Nop>', helpers.exec_capture('nmap asdf')) - end) end) |