summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-01-19 22:51:48 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-19 22:51:48 +0000
commitf61c89d2e698e287a9d04c0a29f4ecc0130c2ea2 (patch)
tree81dccba7f2ae6b868dd30b0f14db444b2f3383fb
parentbed34f0a8a4e38a72a080184881bc68254a8cdc6 (diff)
downloadvim-git-f61c89d2e698e287a9d04c0a29f4ecc0130c2ea2.tar.gz
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to failv8.2.4148
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)
-rw-r--r--src/getchar.c5
-rw-r--r--src/map.c2
-rw-r--r--src/proto/getchar.pro2
-rw-r--r--src/testdir/test_mapping.vim16
-rw-r--r--src/version.c2
5 files changed, 23 insertions, 4 deletions
diff --git a/src/getchar.c b/src/getchar.c
index ff7195231..c0dfc2b0b 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -3836,8 +3836,9 @@ do_cmdkey_command(int key UNUSED, int flags)
#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
index f16397a23..ff117dc6d 100644
--- 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
index 2d791e5c4..a0342577d 100644
--- 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
index a556362ba..69de22ba4 100644
--- 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 <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
func Test_script_local_remap()
new
diff --git a/src/version.c b/src/version.c
index 1ca0a226c..d9307eccb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4148,
+/**/
4147,
/**/
4146,