Skip to content

Commit

Permalink
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
brammool committed Jan 19, 2022
1 parent bed34f0 commit f61c89d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/proto/getchar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 : */
16 changes: 16 additions & 0 deletions src/testdir/test_mapping.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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>

This comment has been minimized.

Copy link
@lacygoill

lacygoill Jan 19, 2022

Not sure it matters for a test, but maybe the autocmd should be limited to one firing:

diff --git a/src/testdir/test_mapping.vim b/src/testdir/test_mapping.vim
index 69de22ba4..5e1150cac 100644
--- a/src/testdir/test_mapping.vim
+++ b/src/testdir/test_mapping.vim
@@ -1444,7 +1444,7 @@ func Test_map_script_cmd_survives_unmap()
       vim9script
       var n = 123
       nnoremap <F4> <ScriptCmd><CR>
-      autocmd CmdlineEnter * silent! nunmap <F4>
+      autocmd CmdlineEnter * ++once silent! nunmap <F4>
       nnoremap <F3> :<ScriptCmd>eval setbufvar(bufnr(), "result", n)<CR>
       feedkeys("\<F3>\<CR>", 'xct')
       assert_equal(123, b:result)

Otherwise, it might still hang around after the test has finished, and maybe disturb the next tests. I don't know.

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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4148,
/**/
4147,
/**/
Expand Down

0 comments on commit f61c89d

Please sign in to comment.