mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 8.2.4107: script context not restored after using <ScriptCmd>
Problem: Script context not restored after using <ScriptCmd>. Solution: Also restore context when not in a script. (closes #9536) Add the 'c' flag to feedkeys() to be able to test this.
This commit is contained in:
@@ -2394,6 +2394,9 @@ feedkeys({string} [, {mode}]) *feedkeys()*
|
|||||||
Note that if you manage to call feedkeys() while
|
Note that if you manage to call feedkeys() while
|
||||||
executing commands, thus calling it recursively, then
|
executing commands, thus calling it recursively, then
|
||||||
all typeahead will be consumed by the last call.
|
all typeahead will be consumed by the last call.
|
||||||
|
'c' Remove any script context when executing, so that
|
||||||
|
legacy script syntax applies, "s:var" does not work,
|
||||||
|
etc.
|
||||||
'!' When used with 'x' will not end Insert mode. Can be
|
'!' When used with 'x' will not end Insert mode. Can be
|
||||||
used in a test when a timer is set to exit Insert mode
|
used in a test when a timer is set to exit Insert mode
|
||||||
a little later. Useful for testing CursorHoldI.
|
a little later. Useful for testing CursorHoldI.
|
||||||
|
@@ -3932,6 +3932,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
char_u nbuf[NUMBUFLEN];
|
char_u nbuf[NUMBUFLEN];
|
||||||
int typed = FALSE;
|
int typed = FALSE;
|
||||||
int execute = FALSE;
|
int execute = FALSE;
|
||||||
|
int context = FALSE;
|
||||||
int dangerous = FALSE;
|
int dangerous = FALSE;
|
||||||
int lowlevel = FALSE;
|
int lowlevel = FALSE;
|
||||||
char_u *keys_esc;
|
char_u *keys_esc;
|
||||||
@@ -3961,6 +3962,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
case 't': typed = TRUE; break;
|
case 't': typed = TRUE; break;
|
||||||
case 'i': insert = TRUE; break;
|
case 'i': insert = TRUE; break;
|
||||||
case 'x': execute = TRUE; break;
|
case 'x': execute = TRUE; break;
|
||||||
|
case 'c': context = TRUE; break;
|
||||||
case '!': dangerous = TRUE; break;
|
case '!': dangerous = TRUE; break;
|
||||||
case 'L': lowlevel = TRUE; break;
|
case 'L': lowlevel = TRUE; break;
|
||||||
}
|
}
|
||||||
@@ -4007,11 +4009,19 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
|
|
||||||
if (execute)
|
if (execute)
|
||||||
{
|
{
|
||||||
int save_msg_scroll = msg_scroll;
|
int save_msg_scroll = msg_scroll;
|
||||||
|
sctx_T save_sctx;
|
||||||
|
|
||||||
// Avoid a 1 second delay when the keys start Insert mode.
|
// Avoid a 1 second delay when the keys start Insert mode.
|
||||||
msg_scroll = FALSE;
|
msg_scroll = FALSE;
|
||||||
|
|
||||||
|
if (context)
|
||||||
|
{
|
||||||
|
save_sctx = current_sctx;
|
||||||
|
current_sctx.sc_sid = 0;
|
||||||
|
current_sctx.sc_version = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!dangerous)
|
if (!dangerous)
|
||||||
{
|
{
|
||||||
++ex_normal_busy;
|
++ex_normal_busy;
|
||||||
@@ -4025,6 +4035,9 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg_scroll |= save_msg_scroll;
|
msg_scroll |= save_msg_scroll;
|
||||||
|
|
||||||
|
if (context)
|
||||||
|
current_sctx = save_sctx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3797,7 +3797,7 @@ getcmdkeycmd(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ga_append(&line_ga, (char)c1);
|
ga_append(&line_ga, c1);
|
||||||
|
|
||||||
cmod = 0;
|
cmod = 0;
|
||||||
}
|
}
|
||||||
@@ -3815,7 +3815,7 @@ do_cmdkey_command(int key UNUSED, int flags)
|
|||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
sctx_T save_current_sctx = {0, 0, 0, 0};
|
sctx_T save_current_sctx = {-1, 0, 0, 0};
|
||||||
|
|
||||||
if (key == K_SCRIPT_COMMAND && last_used_map != NULL)
|
if (key == K_SCRIPT_COMMAND && last_used_map != NULL)
|
||||||
{
|
{
|
||||||
@@ -3827,7 +3827,7 @@ do_cmdkey_command(int key UNUSED, int flags)
|
|||||||
res = do_cmdline(NULL, getcmdkeycmd, NULL, flags);
|
res = do_cmdline(NULL, getcmdkeycmd, NULL, flags);
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
if (save_current_sctx.sc_sid > 0)
|
if (save_current_sctx.sc_sid >= 0)
|
||||||
current_sctx = save_current_sctx;
|
current_sctx = save_current_sctx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ source shared.vim
|
|||||||
source check.vim
|
source check.vim
|
||||||
source screendump.vim
|
source screendump.vim
|
||||||
source term_util.vim
|
source term_util.vim
|
||||||
|
source vim9.vim
|
||||||
|
|
||||||
func Test_abbreviation()
|
func Test_abbreviation()
|
||||||
" abbreviation with 0x80 should work
|
" abbreviation with 0x80 should work
|
||||||
@@ -1397,6 +1398,19 @@ func Test_map_cmdkey_redo()
|
|||||||
ounmap i-
|
ounmap i-
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_map_script_cmd_restore()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
nnoremap <F3> <ScriptCmd>eval 1 + 2<CR>
|
||||||
|
END
|
||||||
|
call CheckScriptSuccess(lines)
|
||||||
|
call feedkeys("\<F3>:let g:result = 3+4\<CR>", 'xtc')
|
||||||
|
call assert_equal(7, g:result)
|
||||||
|
|
||||||
|
nunmap <F3>
|
||||||
|
unlet g: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
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
4107,
|
||||||
/**/
|
/**/
|
||||||
4106,
|
4106,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user