]> granicus.if.org Git - vim/commitdiff
patch 8.2.3537: mode() does not return the right value in 'operatorfunc' v8.2.3537
authornaohiro ono <obcat@icloud.com>
Tue, 19 Oct 2021 10:15:41 +0000 (11:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Oct 2021 10:15:41 +0000 (11:15 +0100)
Problem:    mode() does not return the right value in 'operatorfunc'.
Solution:   Reset finish_op while calling 'operatorfunc'.

src/ops.c
src/testdir/test_functions.vim
src/version.c

index dedeebfb288971cbb1cafb6df1d6195f483948c6..5a48550146bdfefb886ff78dae5834083f08aa39 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -3314,6 +3314,7 @@ op_function(oparg_T *oap UNUSED)
 #ifdef FEAT_EVAL
     typval_T   argv[2];
     int                save_virtual_op = virtual_op;
+    int                save_finish_op = finish_op;
     pos_T      orig_start = curbuf->b_op_start;
     pos_T      orig_end = curbuf->b_op_end;
 
@@ -3341,9 +3342,13 @@ op_function(oparg_T *oap UNUSED)
        // function.
        virtual_op = MAYBE;
 
+       // Reset finish_op so that mode() returns the right value.
+       finish_op = FALSE;
+
        (void)call_func_noret(p_opfunc, 1, argv);
 
        virtual_op = save_virtual_op;
+       finish_op = save_finish_op;
        if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
        {
            curbuf->b_op_start = orig_start;
index 7dd1894fa1db2dc150302889475a5f54cfc60ad7..ac9bb4cfabdd98b78e74e8418344e681b16805cb 100644 (file)
@@ -912,6 +912,20 @@ func Test_mode()
   call assert_equal('c-ce', g:current_modes)
   " How to test Ex mode?
 
+  " Test mode in operatorfunc (it used to be Operator-pending).
+  set operatorfunc=OperatorFunc
+  function OperatorFunc(_)
+    call Save_mode()
+  endfunction
+  execute "normal! g@l\<Esc>"
+  call assert_equal('n-n', g:current_modes)
+  execute "normal! i\<C-o>g@l\<Esc>"
+  call assert_equal('n-niI', g:current_modes)
+  execute "normal! R\<C-o>g@l\<Esc>"
+  call assert_equal('n-niR', g:current_modes)
+  execute "normal! gR\<C-o>g@l\<Esc>"
+  call assert_equal('n-niV', g:current_modes)
+
   if has('terminal')
     term
     call feedkeys("\<C-W>N", 'xt')
@@ -924,6 +938,8 @@ func Test_mode()
   iunmap <F2>
   xunmap <F2>
   set complete&
+  set operatorfunc&
+  delfunction OperatorFunc
 endfunc
 
 " Test for append()
index 204988911c9a9dc81a06a9e3e096808419669559..2e076cbee1ad76b40d66752ff5d9d53ec3e334e2 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3537,
 /**/
     3536,
 /**/