forked from aniani/vim
patch 8.2.0812: mapset() does not properly handle <> notation
Problem: mapset() does not properly handle <> notation. Solution: Convert <> codes. (closes #6116)
This commit is contained in:
@@ -2269,6 +2269,8 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
dict_T *d;
|
dict_T *d;
|
||||||
char_u *lhs;
|
char_u *lhs;
|
||||||
char_u *rhs;
|
char_u *rhs;
|
||||||
|
char_u *orig_rhs;
|
||||||
|
char_u *arg_buf = NULL;
|
||||||
int noremap;
|
int noremap;
|
||||||
int expr;
|
int expr;
|
||||||
int silent;
|
int silent;
|
||||||
@@ -2304,6 +2306,9 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
emsg(_("E99: rhs entry missing in mapset() dict argument"));
|
emsg(_("E99: rhs entry missing in mapset() dict argument"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
orig_rhs = rhs;
|
||||||
|
rhs = replace_termcodes(rhs, &arg_buf,
|
||||||
|
REPTERM_DO_LT | REPTERM_SPECIAL, NULL);
|
||||||
|
|
||||||
noremap = dict_get_number(d, (char_u *)"noremap") ? REMAP_NONE: 0;
|
noremap = dict_get_number(d, (char_u *)"noremap") ? REMAP_NONE: 0;
|
||||||
if (dict_get_number(d, (char_u *)"script") != 0)
|
if (dict_get_number(d, (char_u *)"script") != 0)
|
||||||
@@ -2330,9 +2335,10 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
|
|
||||||
keys = replace_termcodes(lhs, &keys_buf,
|
keys = replace_termcodes(lhs, &keys_buf,
|
||||||
REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
|
REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
|
||||||
(void)map_add(map_table, abbr_table, keys, rhs, rhs, noremap,
|
(void)map_add(map_table, abbr_table, keys, rhs, orig_rhs, noremap,
|
||||||
nowait, silent, mode, is_abbr, expr, sid, lnum, simplified);
|
nowait, silent, mode, is_abbr, expr, sid, lnum, simplified);
|
||||||
vim_free(keys_buf);
|
vim_free(keys_buf);
|
||||||
|
vim_free(arg_buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@ func s:SID()
|
|||||||
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
|
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
funct Test_maparg()
|
func Test_maparg()
|
||||||
new
|
new
|
||||||
set cpo-=<
|
set cpo-=<
|
||||||
set encoding=utf8
|
set encoding=utf8
|
||||||
@@ -156,6 +156,73 @@ endfunc
|
|||||||
func Test_mapset()
|
func Test_mapset()
|
||||||
call One_mapset_test('K')
|
call One_mapset_test('K')
|
||||||
call One_mapset_test('<F3>')
|
call One_mapset_test('<F3>')
|
||||||
|
|
||||||
|
" Check <> key conversion
|
||||||
|
new
|
||||||
|
inoremap K one<Left>x
|
||||||
|
call feedkeys("iK\<Esc>", 'xt')
|
||||||
|
call assert_equal('onxe', getline(1))
|
||||||
|
|
||||||
|
let orig = maparg('K', 'i', 0, 1)
|
||||||
|
call assert_equal('K', orig.lhs)
|
||||||
|
call assert_equal('one<Left>x', orig.rhs)
|
||||||
|
call assert_equal('i', orig.mode)
|
||||||
|
|
||||||
|
iunmap K
|
||||||
|
let d = maparg('K', 'i', 0, 1)
|
||||||
|
call assert_equal({}, d)
|
||||||
|
|
||||||
|
call mapset('i', 0, orig)
|
||||||
|
call feedkeys("SK\<Esc>", 'xt')
|
||||||
|
call assert_equal('onxe', getline(1))
|
||||||
|
|
||||||
|
iunmap K
|
||||||
|
|
||||||
|
" Test literal <CR> using a backslash
|
||||||
|
let cpo_save = &cpo
|
||||||
|
set cpo-=B
|
||||||
|
inoremap K one\<CR>two
|
||||||
|
call feedkeys("SK\<Esc>", 'xt')
|
||||||
|
call assert_equal('one<CR>two', getline(1))
|
||||||
|
|
||||||
|
let orig = maparg('K', 'i', 0, 1)
|
||||||
|
call assert_equal('K', orig.lhs)
|
||||||
|
call assert_equal('one\<CR>two', orig.rhs)
|
||||||
|
call assert_equal('i', orig.mode)
|
||||||
|
|
||||||
|
iunmap K
|
||||||
|
let d = maparg('K', 'i', 0, 1)
|
||||||
|
call assert_equal({}, d)
|
||||||
|
|
||||||
|
call mapset('i', 0, orig)
|
||||||
|
call feedkeys("SK\<Esc>", 'xt')
|
||||||
|
call assert_equal('one<CR>two', getline(1))
|
||||||
|
|
||||||
|
iunmap K
|
||||||
|
let &cpo = cpo_save
|
||||||
|
|
||||||
|
" Test literal <CR> using CTRL-V
|
||||||
|
inoremap K one<CR>two
|
||||||
|
call feedkeys("SK\<Esc>", 'xt')
|
||||||
|
call assert_equal('one<CR>two', getline(1))
|
||||||
|
|
||||||
|
let orig = maparg('K', 'i', 0, 1)
|
||||||
|
call assert_equal('K', orig.lhs)
|
||||||
|
call assert_equal("one\x16<CR>two", orig.rhs)
|
||||||
|
call assert_equal('i', orig.mode)
|
||||||
|
|
||||||
|
iunmap K
|
||||||
|
let d = maparg('K', 'i', 0, 1)
|
||||||
|
call assert_equal({}, d)
|
||||||
|
|
||||||
|
call mapset('i', 0, orig)
|
||||||
|
call feedkeys("SK\<Esc>", 'xt')
|
||||||
|
call assert_equal('one<CR>two', getline(1))
|
||||||
|
|
||||||
|
iunmap K
|
||||||
|
let &cpo = cpo_save
|
||||||
|
|
||||||
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
812,
|
||||||
/**/
|
/**/
|
||||||
811,
|
811,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user