# HG changeset patch # User Bram Moolenaar # Date 1606850104 -3600 # Node ID 57b6427c18e4d7e4c713c84528a6ee189c7b9ab0 # Parent 7de34bbfebf092b54ecf2d8d6f63866da63d73d6 patch 8.2.2074: Vim9: using :normal from Vim9 script can't handle range Commit: https://github.com/vim/vim/commit/4324d87a4432721d9dbc72c1e336350bc6b7ebc3 Author: Bram Moolenaar Date: Tue Dec 1 20:12:24 2020 +0100 patch 8.2.2074: Vim9: using :normal from Vim9 script can't handle range Problem: Vim9: using :normal from Vim9 script can't handle range. Solution: Execute a :normal command in legacy script context. (closes https://github.com/vim/vim/issues/7401) diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -7994,10 +7994,12 @@ save_current_state(save_state_T *sst) sst->save_finish_op = finish_op; sst->save_opcount = opcount; sst->save_reg_executing = reg_executing; - - msg_scroll = FALSE; // no msg scrolling in Normal mode - restart_edit = 0; // don't go to Insert mode - p_im = FALSE; // don't use 'insertmode' + sst->save_script_version = current_sctx.sc_version; + + msg_scroll = FALSE; // no msg scrolling in Normal mode + restart_edit = 0; // don't go to Insert mode + p_im = FALSE; // don't use 'insertmode' + current_sctx.sc_version = 1; // not in Vim9 script /* * Save the current typeahead. This is required to allow using ":normal" @@ -8021,6 +8023,7 @@ restore_current_state(save_state_T *sst) opcount = sst->save_opcount; reg_executing = sst->save_reg_executing; msg_didout |= sst->save_msg_didout; // don't reset msg_didout now + current_sctx.sc_version = sst->save_script_version; // Restore the state (needed when called from a function executed for // 'indentexpr'). Update the mouse and cursor, they may have changed. diff --git a/src/structs.h b/src/structs.h --- a/src/structs.h +++ b/src/structs.h @@ -4155,6 +4155,7 @@ typedef struct { int save_finish_op; int save_opcount; int save_reg_executing; + int save_script_version; tasave_T tabuf; } save_state_T; diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2958,6 +2958,19 @@ def Test_put_with_linebreak() bwipe! enddef +def InvokeNormal() + exe "norm! :m+1\r" +enddef + +def Test_invoke_normal_in_visual_mode() + xnoremap call InvokeNormal() + new + setline(1, ['aaa', 'bbb']) + feedkeys("V\", 'xt') + assert_equal(['bbb', 'aaa'], getline(1, 2)) + xunmap +enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new diff --git a/src/version.c b/src/version.c --- 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 */ /**/ + 2074, +/**/ 2073, /**/ 2072,