Patch 8.2.4148
Problem:    Deleting any mapping may cause <ScriptCmd> to not set the script
            context.
Solution:   Only reset last_used_map if it is the deleted mapping.
            (closes #9568)
Files:      src/map.c, src/getchar.c, src/proto/getchar.pro,
            src/testdir/test_mapping.vim


*** ../vim-8.2.4147/src/map.c   2022-01-18 20:51:29.702559521 +0000
--- src/map.c   2022-01-19 22:30:39.167049010 +0000
***************
*** 86,92 ****
      *mpp = mp->m_next;
      vim_free(mp);
  #ifdef FEAT_EVAL
!     reset_last_used_map();
  #endif
  }
  
--- 86,92 ----
      *mpp = mp->m_next;
      vim_free(mp);
  #ifdef FEAT_EVAL
!     reset_last_used_map(mp);
  #endif
  }
  
*** ../vim-8.2.4147/src/getchar.c       2022-01-16 13:30:29.877688041 +0000
--- src/getchar.c       2022-01-19 22:47:02.183384369 +0000
***************
*** 3836,3843 ****
  
  #if defined(FEAT_EVAL) || defined(PROTO)
      void
! reset_last_used_map(void)
  {
!     last_used_map = NULL;
  }
  #endif
--- 3836,3844 ----
  
  #if defined(FEAT_EVAL) || defined(PROTO)
      void
! reset_last_used_map(mapblock_T *mp)
  {
!     if (last_used_map == mp)
!       last_used_map = NULL;
  }
  #endif
*** ../vim-8.2.4147/src/proto/getchar.pro       2022-01-15 18:25:04.657419390 
+0000
--- src/proto/getchar.pro       2022-01-19 22:32:34.308900441 +0000
***************
*** 53,57 ****
  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);
  /* vim: set ft=c : */
--- 53,57 ----
  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(mapblock_T *mp);
  /* vim: set ft=c : */
*** ../vim-8.2.4147/src/testdir/test_mapping.vim        2022-01-18 
20:30:31.408458462 +0000
--- src/testdir/test_mapping.vim        2022-01-19 22:46:38.071877216 +0000
***************
*** 1439,1444 ****
--- 1439,1460 ----
    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
*** ../vim-8.2.4147/src/version.c       2022-01-19 20:48:33.496661246 +0000
--- src/version.c       2022-01-19 22:51:10.358369349 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4148,
  /**/

-- 
Be nice to your kids...  they'll be the ones choosing your nursing home.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220119225514.DE8AA1C11B3%40moolenaar.net.

Raspunde prin e-mail lui