]> granicus.if.org Git - vim/commitdiff
patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone v8.2.3644
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Nov 2021 14:16:08 +0000 (14:16 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Nov 2021 14:16:08 +0000 (14:16 +0000)
Problem:    Count for 'operatorfunc' in Visual mode is not redone.
Solution:   Add the count to the redo buffer. (closes #9174)

src/normal.c
src/ops.c
src/proto/normal.pro
src/testdir/test_normal.vim
src/version.c

index aab336a5fe90576328e9a90f4714b6be6d53e6d9..56fae51dacf25c750a97aed79859e327a92bc2b0 100644 (file)
@@ -380,8 +380,10 @@ static const struct nv_cmd
 // Number of commands in nv_cmds[].
 #define NV_CMDS_SIZE ARRAY_LENGTH(nv_cmds)
 
+#ifndef PROTO  // cproto doesn't like this
 // Sorted index of commands in nv_cmds[].
 static short nv_cmd_idx[NV_CMDS_SIZE];
+#endif
 
 // The highest index for which
 // nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char]
@@ -1696,6 +1698,23 @@ prep_redo(
     int            cmd3,
     int            cmd4,
     int            cmd5)
+{
+    prep_redo_num2(regname, num, cmd1, cmd2, 0L, cmd3, cmd4, cmd5);
+}
+
+/*
+ * Prepare for redo of any command with extra count after "cmd2".
+ */
+    void
+prep_redo_num2(
+    int            regname,
+    long    num1,
+    int            cmd1,
+    int            cmd2,
+    long    num2,
+    int            cmd3,
+    int            cmd4,
+    int            cmd5)
 {
     ResetRedobuff();
     if (regname != 0)  // yank from specified buffer
@@ -1703,13 +1722,14 @@ prep_redo(
        AppendCharToRedobuff('"');
        AppendCharToRedobuff(regname);
     }
-    if (num)
-       AppendNumberToRedobuff(num);
-
+    if (num1 != 0)
+       AppendNumberToRedobuff(num1);
     if (cmd1 != NUL)
        AppendCharToRedobuff(cmd1);
     if (cmd2 != NUL)
        AppendCharToRedobuff(cmd2);
+    if (num2 != 0)
+       AppendNumberToRedobuff(num2);
     if (cmd3 != NUL)
        AppendCharToRedobuff(cmd3);
     if (cmd4 != NUL)
index aa3b5dec4cd3d5f86d64d5ea64aa70cec30226e7..d6190641da552618b48a97ca236c302f2064934d 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -3764,6 +3764,8 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
                            oap->motion_force, cap->cmdchar, cap->nchar);
                else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND)
                {
+                   int opchar = get_op_char(oap->op_type);
+                   int extra_opchar = get_extra_op_char(oap->op_type);
                    int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;
 
                    // reverse what nv_replace() did
@@ -3771,10 +3773,14 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
                        nchar = CAR;
                    else if (nchar == REPLACE_NL_NCHAR)
                        nchar = NL;
-                   prep_redo(oap->regname, 0L, NUL, 'v',
-                                       get_op_char(oap->op_type),
-                                       get_extra_op_char(oap->op_type),
-                                       nchar);
+
+                   if (opchar == 'g' && extra_opchar == '@')
+                       // also repeat the count for 'operatorfunc'
+                       prep_redo_num2(oap->regname, 0L, NUL, 'v',
+                                    cap->count0, opchar, extra_opchar, nchar);
+                   else
+                       prep_redo(oap->regname, 0L, NUL, 'v',
+                                                 opchar, extra_opchar, nchar);
                }
                if (!redo_VIsual_busy)
                {
index 30f360b9353162dfc5ab9861da1ce781925fe6d1..ad0e95ab5c957db5b7b70c47f4c1f6e88f948b16 100644 (file)
@@ -10,6 +10,7 @@ void restore_visual_mode(void);
 int find_ident_under_cursor(char_u **text, int find_type);
 int find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **text, int *textcol, int find_type);
 void prep_redo(int regname, long num, int cmd1, int cmd2, int cmd3, int cmd4, int cmd5);
+void prep_redo_num2(int regname, long num1, int cmd1, int cmd2, long num2, int cmd3, int cmd4, int cmd5);
 void clearop(oparg_T *oap);
 void clearopbeep(oparg_T *oap);
 void may_clear_cmdline(void);
index fd2e2ecf1c0b8733de3a3c2624da48c9c4a1816e..e17aca4128d733e346ec5ec1f026008185a2ab24 100644 (file)
@@ -363,7 +363,7 @@ func Test_normal08_fold()
   bw!
 endfunc
 
-func Test_normal09_operatorfunc()
+func Test_normal09a_operatorfunc()
   " Test operatorfunc
   call Setup_NewWindow()
   " Add some spaces for counting
@@ -457,7 +457,7 @@ func Test_normal09_operatorfunc()
   bw!
 endfunc
 
-func Test_normal09a_operatorfunc()
+func Test_normal09b_operatorfunc()
   " Test operatorfunc
   call Setup_NewWindow()
   " Add some spaces for counting
@@ -484,6 +484,26 @@ func Test_normal09a_operatorfunc()
   unlet! g:opt
 endfunc
 
+func OperatorfuncRedo(_)
+  let g:opfunc_count = v:count
+endfunc
+
+func Test_normal09c_operatorfunc()
+  " Test redoing operatorfunc
+  new
+  call setline(1, 'some text')
+  set operatorfunc=OperatorfuncRedo
+  normal v3g@
+  call assert_equal(3, g:opfunc_count)
+  let g:opfunc_count = 0
+  normal .
+  call assert_equal(3, g:opfunc_count)
+
+  bw!
+  unlet g:opfunc_count
+  set operatorfunc=
+endfunc
+
 func Test_normal10_expand()
   " Test for expand()
   10new
index cf05293909ad37af467c2af83ce0cc5faf181f47..67b26345227e28b3ccbb2e5144fe9ef4f09ad0e7 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3644,
 /**/
     3643,
 /**/