0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.4867: listing of mapping with K_SPECIAL is wrong

Problem:    Listing of mapping with K_SPECIAL is wrong.
Solution:   Adjust escaping of special characters. (closes #10351)
This commit is contained in:
zeertzjq
2022-05-04 18:51:43 +01:00
committed by Bram Moolenaar
parent 47d4e317f8
commit ac402f4d64
4 changed files with 41 additions and 19 deletions

View File

@@ -189,17 +189,7 @@ showmap(
if (*mp->m_str == NUL) if (*mp->m_str == NUL)
msg_puts_attr("<Nop>", HL_ATTR(HLF_8)); msg_puts_attr("<Nop>", HL_ATTR(HLF_8));
else else
{ msg_outtrans_special(mp->m_str, FALSE, 0);
// 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);
}
}
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
if (p_verbose > 0) if (p_verbose > 0)
last_set_msg(mp->m_script_ctx); last_set_msg(mp->m_script_ctx);

View File

@@ -1799,20 +1799,30 @@ str2special(
} }
if (has_mbyte && !IS_SPECIAL(c)) if (has_mbyte && !IS_SPECIAL(c))
{
char_u *p;
*sp = str;
// Try to un-escape a multi-byte character after modifiers.
p = mb_unescape(sp);
if (p == NULL)
{ {
int len = (*mb_ptr2len)(str); int len = (*mb_ptr2len)(str);
// For multi-byte characters check for an illegal byte. // Check for an illegal byte.
if (MB_BYTE2LEN(*str) > len) if (MB_BYTE2LEN(*str) > len)
{ {
transchar_nonprint(curbuf, buf, c); transchar_nonprint(curbuf, buf, c);
*sp = str + 1; *sp = str + 1;
return buf; return buf;
} }
*sp = str + len;
p = str;
}
// Since 'special' is TRUE the multi-byte character 'c' will be // Since 'special' is TRUE the multi-byte character 'c' will be
// processed by get_special_key_name() // processed by get_special_key_name()
c = (*mb_ptr2char)(str); c = (*mb_ptr2char)(p);
*sp = str + len;
} }
else else
*sp = str + 1; *sp = str + 1;

View File

@@ -482,6 +482,26 @@ func Test_list_mappings()
call assert_match("\tLast set from .*/test_mapping.vim line \\d\\+$", call assert_match("\tLast set from .*/test_mapping.vim line \\d\\+$",
\ execute('verbose map ,n')->trim()->split("\n")[1]) \ 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
nmapfoo
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 " map to CTRL-V
exe "nmap ,k \<C-V>" exe "nmap ,k \<C-V>"
call assert_equal(['n ,k <Nop>'], call assert_equal(['n ,k <Nop>'],

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4867,
/**/ /**/
4866, 4866,
/**/ /**/