]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4867: listing of mapping with K_SPECIAL is wrong v8.2.4867
authorzeertzjq <zeertzjq@outlook.com>
Wed, 4 May 2022 17:51:43 +0000 (18:51 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 4 May 2022 17:51:43 +0000 (18:51 +0100)
Problem:    Listing of mapping with K_SPECIAL is wrong.
Solution:   Adjust escaping of special characters. (closes #10351)

src/map.c
src/message.c
src/testdir/test_mapping.vim
src/version.c

index 6ea73ebce2934b491f18d0c262ff872381a6676d..762cce2d5fc9e7aa2e7cff08df80e124fe7ff0d2 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -189,17 +189,7 @@ showmap(
     if (*mp->m_str == NUL)
        msg_puts_attr("<Nop>", HL_ATTR(HLF_8));
     else
-    {
-       // Remove escaping of CSI, because "m_str" is in a format to be used
-       // as typeahead.
-       char_u *s = vim_strsave(mp->m_str);
-       if (s != NULL)
-       {
-           vim_unescape_csi(s);
-           msg_outtrans_special(s, FALSE, 0);
-           vim_free(s);
-       }
-    }
+       msg_outtrans_special(mp->m_str, FALSE, 0);
 #ifdef FEAT_EVAL
     if (p_verbose > 0)
        last_set_msg(mp->m_script_ctx);
index 2499723e4d404012fa124996a28c6d958aefaa20..b5b00f33fefeed9cc38a6b8fd396b7c904d16490 100644 (file)
@@ -1800,19 +1800,29 @@ str2special(
 
     if (has_mbyte && !IS_SPECIAL(c))
     {
-       int len = (*mb_ptr2len)(str);
+       char_u  *p;
+
+       *sp = str;
+       // Try to un-escape a multi-byte character after modifiers.
+       p = mb_unescape(sp);
 
-       // For multi-byte characters check for an illegal byte.
-       if (MB_BYTE2LEN(*str) > len)
+       if (p == NULL)
        {
-           transchar_nonprint(curbuf, buf, c);
-           *sp = str + 1;
-           return buf;
+           int len = (*mb_ptr2len)(str);
+
+           // Check for an illegal byte.
+           if (MB_BYTE2LEN(*str) > len)
+           {
+               transchar_nonprint(curbuf, buf, c);
+               *sp = str + 1;
+               return buf;
+           }
+           *sp = str + len;
+           p = str;
        }
        // Since 'special' is TRUE the multi-byte character 'c' will be
        // processed by get_special_key_name()
-       c = (*mb_ptr2char)(str);
-       *sp = str + len;
+       c = (*mb_ptr2char)(p);
     }
     else
        *sp = str + 1;
index 7f768cf80f74de59b6bd44d21d0c2c23c5c56026..e886424fb1bdc85a2a332ded6626aad04277380f 100644 (file)
@@ -482,6 +482,26 @@ func Test_list_mappings()
   call assert_match("\tLast set from .*/test_mapping.vim line \\d\\+$",
         \ execute('verbose map ,n')->trim()->split("\n")[1])
 
+  " character with K_SPECIAL byte in rhs
+  nmap foo …
+  call assert_equal(['n  foo           …'],
+        \ execute('nmap foo')->trim()->split("\n"))
+
+  " modified character with K_SPECIAL byte in rhs
+  nmap foo <M-…>
+  call assert_equal(['n  foo           <M-…>'],
+        \ execute('nmap foo')->trim()->split("\n"))
+
+  " character with K_SPECIAL byte in lhs
+  nmap … foo
+  call assert_equal(['n  …             foo'],
+        \ execute('nmap …')->trim()->split("\n"))
+
+  " modified character with K_SPECIAL byte in lhs
+  nmap <M-…> foo
+  call assert_equal(['n  <M-…>         foo'],
+        \ execute('nmap <M-…>')->trim()->split("\n"))
+
   " map to CTRL-V
   exe "nmap ,k \<C-V>"
   call assert_equal(['n  ,k            <Nop>'],
index 17bcfd1f4fb17fcc41ae2d99c2d405908cd5a989..d04a226688360a6cc2af949d475abf8aa9297a5d 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4867,
 /**/
     4866,
 /**/