]> granicus.if.org Git - vim/commitdiff
patch 8.2.2074: Vim9: using :normal from Vim9 script can't handle range v8.2.2074
authorBram Moolenaar <Bram@vim.org>
Tue, 1 Dec 2020 19:12:24 +0000 (20:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 1 Dec 2020 19:12:24 +0000 (20:12 +0100)
Problem:    Vim9: using :normal from Vim9 script can't handle range.
Solution:   Execute a :normal command in legacy script context. (closes #7401)

src/ex_docmd.c
src/structs.h
src/testdir/test_vim9_script.vim
src/version.c

index 1d5d2dedc23d04486e28eb9a10bfc22e382b7ac8..e7aec5e2ab78e6fd64f9551d87cc66940c4cc894 100644 (file)
@@ -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;
+    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'
+    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.
index 24baa34c5123b544ae57195a53b8a7a5c82efe3f..b18134ac0a6f4d1a65d119d51e38b6780ff38531 100644 (file)
@@ -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;
 
index b58e566caf6447c5a4e683c01129f6f8a9b26793..a18e3f2a48fbb4a2d2c96b1746bce741f8c296f1 100644 (file)
@@ -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 <F3> <Cmd>call <SID>InvokeNormal()<CR>
+  new
+  setline(1, ['aaa', 'bbb'])
+  feedkeys("V\<F3>", 'xt')
+  assert_equal(['bbb', 'aaa'], getline(1, 2))
+  xunmap <F3>
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
index a4d6eedfc3a90c814ce58ffee87b83fd33b6e832..469b92d3179179d49f544554aa567bce11757c91 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2074,
 /**/
     2073,
 /**/