# HG changeset patch # User Bram Moolenaar # Date 1642633207 -3600 # Node ID bd072d44eb2c6bd6ae72ded13f0498eaf6bcd8cf # Parent 78460f6857a063bde4d82d1509575c61e5c607fc patch 8.2.4148: deleting any mapping may cause to fail Commit: https://github.com/vim/vim/commit/f61c89d2e698e287a9d04c0a29f4ecc0130c2ea2 Author: Bram Moolenaar Date: Wed Jan 19 22:51:48 2022 +0000 patch 8.2.4148: deleting any mapping may cause to fail Problem: Deleting any mapping may cause to not set the script context. Solution: Only reset last_used_map if it is the deleted mapping. (closes #9568) diff --git a/src/getchar.c b/src/getchar.c --- a/src/getchar.c +++ b/src/getchar.c @@ -3836,8 +3836,9 @@ do_cmdkey_command(int key UNUSED, int fl #if defined(FEAT_EVAL) || defined(PROTO) void -reset_last_used_map(void) +reset_last_used_map(mapblock_T *mp) { - last_used_map = NULL; + if (last_used_map == mp) + last_used_map = NULL; } #endif diff --git a/src/map.c b/src/map.c --- a/src/map.c +++ b/src/map.c @@ -86,7 +86,7 @@ map_free(mapblock_T **mpp) *mpp = mp->m_next; vim_free(mp); #ifdef FEAT_EVAL - reset_last_used_map(); + reset_last_used_map(mp); #endif } diff --git a/src/proto/getchar.pro b/src/proto/getchar.pro --- a/src/proto/getchar.pro +++ b/src/proto/getchar.pro @@ -53,5 +53,5 @@ void vungetc(int c); int fix_input_buffer(char_u *buf, int len); int input_available(void); int do_cmdkey_command(int key, int flags); -void reset_last_used_map(void); +void reset_last_used_map(mapblock_T *mp); /* vim: set ft=c : */ diff --git a/src/testdir/test_mapping.vim b/src/testdir/test_mapping.vim --- a/src/testdir/test_mapping.vim +++ b/src/testdir/test_mapping.vim @@ -1439,6 +1439,22 @@ func Test_map_script_cmd_finds_func() unlet g:func_called endfunc +func Test_map_script_cmd_survives_unmap() + let lines =<< trim END + vim9script + var n = 123 + nnoremap + autocmd CmdlineEnter * silent! nunmap + nnoremap :eval setbufvar(bufnr(), "result", n) + feedkeys("\\", 'xct') + assert_equal(123, b:result) + END + call CheckScriptSuccess(lines) + + nunmap + unlet b:result +endfunc + " Test for using