# HG changeset patch # User Bram Moolenaar # Date 1634639405 -7200 # Node ID 1d2e1c23e458daaada582819be9b51eae795f162 # Parent 412aa3ebb70c1b9b95dae2545cac0cff1d2f1da0 patch 8.2.3537: mode() does not return the right value in 'operatorfunc' Commit: https://github.com/vim/vim/commit/75c30e96cf280a8cc01ac01c41a9252db3e503cc Author: naohiro ono Date: Tue Oct 19 11:15:41 2021 +0100 patch 8.2.3537: mode() does not return the right value in 'operatorfunc' Problem: mode() does not return the right value in 'operatorfunc'. Solution: Reset finish_op while calling 'operatorfunc'. diff --git a/src/ops.c b/src/ops.c --- 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; diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -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\" + call assert_equal('n-n', g:current_modes) + execute "normal! i\g@l\" + call assert_equal('n-niI', g:current_modes) + execute "normal! R\g@l\" + call assert_equal('n-niR', g:current_modes) + execute "normal! gR\g@l\" + call assert_equal('n-niV', g:current_modes) + if has('terminal') term call feedkeys("\N", 'xt') @@ -924,6 +938,8 @@ func Test_mode() iunmap xunmap set complete& + set operatorfunc& + delfunction OperatorFunc endfunc " Test for append() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3537, +/**/ 3536, /**/ 3535,