vim-patch:8.2.3537: wrong mode() during 'operatorfunc' #16087

Problem:    mode() does not return the right value in 'operatorfunc'.
Solution:   Reset finish_op while calling 'operatorfunc'.
75c30e96cf
This commit is contained in:
zeertzjq 2021-10-19 22:39:25 +08:00 committed by GitHub
parent bdd180b5d2
commit 308fd88d0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -2167,6 +2167,7 @@ static void op_function(const oparg_T *oap)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
const TriState save_virtual_op = virtual_op; const TriState save_virtual_op = virtual_op;
const bool save_finish_op = finish_op;
if (*p_opfunc == NUL) { if (*p_opfunc == NUL) {
EMSG(_("E774: 'operatorfunc' is empty")); EMSG(_("E774: 'operatorfunc' is empty"));
@ -2193,9 +2194,13 @@ static void op_function(const oparg_T *oap)
// function. // function.
virtual_op = kNone; virtual_op = kNone;
// Reset finish_op so that mode() returns the right value.
finish_op = false;
(void)call_func_retnr(p_opfunc, 1, argv); (void)call_func_retnr(p_opfunc, 1, argv);
virtual_op = save_virtual_op; virtual_op = save_virtual_op;
finish_op = save_finish_op;
} }
} }

View File

@ -711,6 +711,20 @@ func Test_mode()
call assert_equal('c-cv', g:current_modes) call assert_equal('c-cv', g:current_modes)
" How to test Ex mode? " 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') if has('terminal')
term term
call feedkeys("\<C-W>N", 'xt') call feedkeys("\<C-W>N", 'xt')
@ -723,6 +737,8 @@ func Test_mode()
iunmap <F2> iunmap <F2>
xunmap <F2> xunmap <F2>
set complete& set complete&
set operatorfunc&
delfunction OperatorFunc
endfunc endfunc
func Test_append() func Test_append()