0
0
mirror of https://github.com/vim/vim.git synced 2025-10-02 05:04:20 -04:00

patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail

Problem:    Deleting any mapping may cause <ScritpCmd> to not set the script
            context.
Solution:   Only reset last_used_map if it is the deleted mapping.
            (closes #9568)
This commit is contained in:
Bram Moolenaar
2022-01-19 22:51:48 +00:00
parent bed34f0a8a
commit f61c89d2e6
5 changed files with 23 additions and 4 deletions

View File

@@ -3836,8 +3836,9 @@ do_cmdkey_command(int key UNUSED, int flags)
#if defined(FEAT_EVAL) || defined(PROTO) #if defined(FEAT_EVAL) || defined(PROTO)
void 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 #endif

View File

@@ -86,7 +86,7 @@ map_free(mapblock_T **mpp)
*mpp = mp->m_next; *mpp = mp->m_next;
vim_free(mp); vim_free(mp);
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
reset_last_used_map(); reset_last_used_map(mp);
#endif #endif
} }

View File

@@ -53,5 +53,5 @@ void vungetc(int c);
int fix_input_buffer(char_u *buf, int len); int fix_input_buffer(char_u *buf, int len);
int input_available(void); int input_available(void);
int do_cmdkey_command(int key, int flags); 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 : */ /* vim: set ft=c : */

View File

@@ -1439,6 +1439,22 @@ func Test_map_script_cmd_finds_func()
unlet g:func_called unlet g:func_called
endfunc endfunc
func Test_map_script_cmd_survives_unmap()
let lines =<< trim END
vim9script
var n = 123
nnoremap <F4> <ScriptCmd><CR>
autocmd CmdlineEnter * silent! nunmap <F4>
nnoremap <F3> :<ScriptCmd>eval setbufvar(bufnr(), "result", n)<CR>
feedkeys("\<F3>\<CR>", 'xct')
assert_equal(123, b:result)
END
call CheckScriptSuccess(lines)
nunmap <F3>
unlet b:result
endfunc
" Test for using <script> with a map to remap characters in rhs " Test for using <script> with a map to remap characters in rhs
func Test_script_local_remap() func Test_script_local_remap()
new new

View File

@@ -750,6 +750,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 */
/**/
4148,
/**/ /**/
4147, 4147,
/**/ /**/