mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
vim-patch:8.2.0812: mapset() does not properly handle <> notation
Problem: mapset() does not properly handle <> notation.
Solution: Convert <> codes. (closes vim/vim#6116)
c94c1467b9
This commit is contained in:
@@ -2150,6 +2150,9 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
emsg(_("E99: rhs entry missing in mapset() dict argument"));
|
emsg(_("E99: rhs entry missing in mapset() dict argument"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
char *orig_rhs = rhs;
|
||||||
|
char *arg_buf = NULL;
|
||||||
|
rhs = replace_termcodes(rhs, STRLEN(rhs), &arg_buf, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS);
|
||||||
|
|
||||||
int noremap = tv_dict_get_number(d, "noremap") ? REMAP_NONE : 0;
|
int noremap = tv_dict_get_number(d, "noremap") ? REMAP_NONE : 0;
|
||||||
if (tv_dict_get_number(d, "script") != 0) {
|
if (tv_dict_get_number(d, "script") != 0) {
|
||||||
@@ -2158,9 +2161,9 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
// TODO: support "callback" and "desc"
|
// TODO: support "callback" and "desc"
|
||||||
MapArguments args = {
|
MapArguments args = {
|
||||||
.rhs = vim_strsave((char_u *)rhs),
|
.rhs = (char_u *)rhs,
|
||||||
.rhs_lua = LUA_NOREF,
|
.rhs_lua = LUA_NOREF,
|
||||||
.orig_rhs = vim_strsave((char_u *)rhs),
|
.orig_rhs = vim_strsave((char_u *)orig_rhs),
|
||||||
.expr = tv_dict_get_number(d, "expr") != 0,
|
.expr = tv_dict_get_number(d, "expr") != 0,
|
||||||
.silent = tv_dict_get_number(d, "silent") != 0,
|
.silent = tv_dict_get_number(d, "silent") != 0,
|
||||||
.nowait = tv_dict_get_number(d, "nowait") != 0,
|
.nowait = tv_dict_get_number(d, "nowait") != 0,
|
||||||
|
@@ -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
|
||||||
@@ -170,6 +170,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
|
||||||
|
Reference in New Issue
Block a user