mirror of
https://github.com/neovim/neovim.git
synced 2025-12-17 11:55:34 +00:00
vim-patch:8.2.2804: setting buffer local mapping with mapset() changes global
Problem: Setting buffer local mapping with mapset() changes global mapping.
Solution: Only set the local mapping. (closes vim/vim#8143)
7ba1e4d363
This commit is contained in:
@@ -2171,23 +2171,21 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
.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,
|
||||||
};
|
};
|
||||||
|
|
||||||
scid_T sid = (scid_T)tv_dict_get_number(d, "sid");
|
scid_T sid = (scid_T)tv_dict_get_number(d, "sid");
|
||||||
linenr_T lnum = (linenr_T)tv_dict_get_number(d, "lnum");
|
linenr_T lnum = (linenr_T)tv_dict_get_number(d, "lnum");
|
||||||
|
bool buffer = tv_dict_get_number(d, "buffer") != 0;
|
||||||
mapblock_T **map_table = maphash;
|
|
||||||
mapblock_T **abbr_table = &first_abbr;
|
|
||||||
|
|
||||||
if (tv_dict_get_number(d, "buffer") != 0) {
|
|
||||||
map_table = curbuf->b_maphash;
|
|
||||||
abbr_table = &curbuf->b_first_abbr;
|
|
||||||
}
|
|
||||||
// mode from the dict is not used
|
// mode from the dict is not used
|
||||||
|
|
||||||
|
mapblock_T **map_table = buffer ? curbuf->b_maphash : maphash;
|
||||||
|
mapblock_T **abbr_table = buffer ? &curbuf->b_first_abbr : &first_abbr;
|
||||||
|
|
||||||
// Delete any existing mapping for this lhs and mode.
|
// Delete any existing mapping for this lhs and mode.
|
||||||
char_u *arg = vim_strsave((char_u *)lhs);
|
MapArguments unmap_args = MAP_ARGUMENTS_INIT;
|
||||||
do_map(1, arg, mode, is_abbr); // TODO: refactor this later
|
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &unmap_args);
|
||||||
xfree(arg);
|
unmap_args.buffer = buffer;
|
||||||
|
buf_do_map(1, &unmap_args, mode, false, curbuf);
|
||||||
|
xfree(unmap_args.rhs);
|
||||||
|
xfree(unmap_args.orig_rhs);
|
||||||
|
|
||||||
if (lhsrawalt != NULL) {
|
if (lhsrawalt != NULL) {
|
||||||
map_add(curbuf, map_table, abbr_table, (char_u *)lhsrawalt, &args, noremap, mode, is_abbr,
|
map_add(curbuf, map_table, abbr_table, (char_u *)lhsrawalt, &args, noremap, mode, is_abbr,
|
||||||
@@ -2219,7 +2217,7 @@ void f_mapcheck(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
/// @param buffer If true, make a buffer-local mapping for curbuf
|
/// @param buffer If true, make a buffer-local mapping for curbuf
|
||||||
void add_map(char *lhs, char *rhs, int mode, bool buffer)
|
void add_map(char *lhs, char *rhs, int mode, bool buffer)
|
||||||
{
|
{
|
||||||
MapArguments args = { 0 };
|
MapArguments args = MAP_ARGUMENTS_INIT;
|
||||||
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args);
|
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args);
|
||||||
args.buffer = buffer;
|
args.buffer = buffer;
|
||||||
|
|
||||||
|
|||||||
@@ -253,6 +253,27 @@ func Check_ctrlb_map(d, check_alt)
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_map_local()
|
||||||
|
nmap a global
|
||||||
|
nmap <buffer>a local
|
||||||
|
|
||||||
|
let prev_map_list = split(execute('nmap a'), "\n")
|
||||||
|
call assert_match('n\s*a\s*@local', prev_map_list[0])
|
||||||
|
call assert_match('n\s*a\s*global', prev_map_list[1])
|
||||||
|
|
||||||
|
let mapping = maparg('a', 'n', 0, 1)
|
||||||
|
call assert_equal(1, mapping.buffer)
|
||||||
|
let mapping.rhs = 'new_local'
|
||||||
|
call mapset('n', 0, mapping)
|
||||||
|
|
||||||
|
" Check that the global mapping is left untouched.
|
||||||
|
let map_list = split(execute('nmap a'), "\n")
|
||||||
|
call assert_match('n\s*a\s*@new_local', map_list[0])
|
||||||
|
call assert_match('n\s*a\s*global', map_list[1])
|
||||||
|
|
||||||
|
nunmap a
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_map_restore()
|
func Test_map_restore()
|
||||||
" Test restoring map with alternate keycode
|
" Test restoring map with alternate keycode
|
||||||
nmap <C-B> back
|
nmap <C-B> back
|
||||||
|
|||||||
Reference in New Issue
Block a user