]> granicus.if.org Git - vim/commitdiff
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail v8.2.4148
authorBram Moolenaar <Bram@vim.org>
Wed, 19 Jan 2022 22:51:48 +0000 (22:51 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 19 Jan 2022 22:51:48 +0000 (22:51 +0000)
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)

src/getchar.c
src/map.c
src/proto/getchar.pro
src/testdir/test_mapping.vim
src/version.c

index ff71952316d45975e7cdb2dd6a5c6b5c2bc57105..c0dfc2b0b89979d0d413aec9d40de8453a03d79a 100644 (file)
@@ -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
index f16397a231bc664b95423b315decd0d02be9d666..ff117dc6da545c38fa52d51252559d15c34b0014 100644 (file)
--- 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
 }
 
index 2d791e5c489e2601972fee8977d2996de5eb7fd3..a0342577d72ef847d057e8656f7f9f1b97f72ec2 100644 (file)
@@ -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 : */
index a556362ba5b26d49c83a91b9bdbea4abfb992e2a..69de22ba4974585da38942c41683206281c99b71 100644 (file)
@@ -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
index 1ca0a226c2088f6bfc67c951868d1be5371c42fa..d9307eccb69bd291edfc8f2fee3b61bb1cc076fa 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4148,
 /**/
     4147,
 /**/