]> granicus.if.org Git - vim/commitdiff
patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly v8.2.2005
authorBram Moolenaar <Bram@vim.org>
Wed, 18 Nov 2020 10:34:37 +0000 (11:34 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 18 Nov 2020 10:34:37 +0000 (11:34 +0100)
Problem:    Redoing a mapping with <Cmd> doesn't work properly.
Solution:   Fill the redo buffer.  Use "<SNR>" instead of a key code.
            (closes #7282)

src/getchar.c
src/ops.c
src/testdir/test_mapping.vim
src/version.c

index 165a6a3ad7b84256341598bbc4470b757f23ae94..ad21cba7f26e1ab535daaa7f9a77b4d0471e10df 100644 (file)
@@ -3691,11 +3691,7 @@ getcmdkeycmd(
        else if (IS_SPECIAL(c1))
        {
            if (c1 == K_SNR)
-           {
-               ga_append(&line_ga, (char)K_SPECIAL);
-               ga_append(&line_ga, (char)KS_EXTRA);
-               ga_append(&line_ga, (char)KE_SNR);
-           }
+               ga_concat(&line_ga, (char_u *)"<SNR>");
            else
            {
                semsg(e_cmd_maping_must_not_include_str_key,
index cc25683072ab0d7df1be94b17756654e770feb86..417bb1621d6880ac56009d5bf53b72f0c9b6d83a 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -3465,8 +3465,9 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
        if ((redo_yank || oap->op_type != OP_YANK)
                && ((!VIsual_active || oap->motion_force)
                    // Also redo Operator-pending Visual mode mappings
-                   || (VIsual_active && cap->cmdchar == ':'
-                                                && oap->op_type != OP_COLON))
+                   || (VIsual_active
+                         && (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND)
+                                                 && oap->op_type != OP_COLON))
                && cap->cmdchar != 'D'
 #ifdef FEAT_FOLDING
                && oap->op_type != OP_FOLD
@@ -3688,7 +3689,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
                            get_op_char(oap->op_type),
                            get_extra_op_char(oap->op_type),
                            oap->motion_force, cap->cmdchar, cap->nchar);
-               else if (cap->cmdchar != ':')
+               else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND)
                {
                    int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;
 
index dbd0a7e320c9bd5b893d41ef416d09b356439a7d..66edaa80a68edb7cf5b1af97759b41165fdc396c 100644 (file)
@@ -1324,4 +1324,40 @@ func Test_map_cmdkey_cmdline_mode()
   %bw!
 endfunc
 
+func Test_map_cmdkey_redo()
+  func SelectDash()
+    call search('^---\n\zs', 'bcW')
+    norm! V
+    call search('\n\ze---$', 'W')
+  endfunc
+
+  let text =<< trim END
+      ---
+      aaa
+      ---
+      bbb
+      bbb
+      ---
+      ccc
+      ccc
+      ccc
+      ---
+  END
+  new Xcmdtext
+  call setline(1, text)
+
+  onoremap <silent> i- <Cmd>call SelectDash()<CR>
+  call feedkeys('2Gdi-', 'xt')
+  call assert_equal(['---', '---'], getline(1, 2))
+  call feedkeys('j.', 'xt')
+  call assert_equal(['---', '---', '---'], getline(1, 3))
+  call feedkeys('j.', 'xt')
+  call assert_equal(['---', '---', '---', '---'], getline(1, 4))
+
+  bwipe!
+  call delete('Xcmdtext')
+  delfunc SelectDash
+  ounmap i-
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index dafd15bf9488d31b475bd72debff75430fccb8be..2191c340608aaf03d08455872d5a9f8687732e28 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2005,
 /**/
     2004,
 /**/