]> granicus.if.org Git - vim/commitdiff
patch 8.2.4722: ending recording with mapping records too much v8.2.4722
authorzeertzjq <zeertzjq@outlook.com>
Sat, 9 Apr 2022 16:58:49 +0000 (17:58 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 9 Apr 2022 16:58:49 +0000 (17:58 +0100)
Problem:    When a recording is ended with a mapped key that key is also
            recorded.
Solution:   Remember the previous last_recorded_len. (closes #10122)

src/getchar.c
src/testdir/test_registers.vim
src/version.c

index 29ad56e6a176f8084bbc80bbe8c9bd27aee57d6f..fb7f00a95f98bc41389f33150e96cde483e519d2 100644 (file)
@@ -1705,10 +1705,16 @@ vgetc(void)
     }
     else
     {
+       // number of characters recorded from the last vgetc() call
+       static int      last_vgetc_recorded_len = 0;
+
        mod_mask = 0;
        vgetc_mod_mask = 0;
        vgetc_char = 0;
-       last_recorded_len = 0;
+
+       // last_recorded_len can be larger than last_vgetc_recorded_len
+       // if peeking records more
+       last_recorded_len -= last_vgetc_recorded_len;
 
        for (;;)                // this is done twice if there are modifiers
        {
@@ -1910,6 +1916,8 @@ vgetc(void)
 
            break;
        }
+
+       last_vgetc_recorded_len = last_recorded_len;
     }
 
 #ifdef FEAT_EVAL
index 51543c00c1f789476965264399dec2c2108e3fbc..352264981283bb914bb35b45776a547991b29ff9 100644 (file)
@@ -759,6 +759,27 @@ func Test_record_in_select_mode()
   bwipe!
 endfunc
 
+" mapping that ends macro recording should be removed from recorded macro
+func Test_end_record_using_mapping()
+  call setline(1, 'aaa')
+  nnoremap s q
+  call feedkeys('safas', 'tx')
+  call assert_equal('fa', @a)
+  nunmap s
+
+  nnoremap xx q
+  call feedkeys('0xxafaxx', 'tx')
+  call assert_equal('fa', @a)
+  nunmap xx
+
+  nnoremap xsx q
+  call feedkeys('0qafaxsx', 'tx')
+  call assert_equal('fa', @a)
+  nunmap xsx
+
+  bwipe!
+endfunc
+
 func Test_end_reg_executing()
   nnoremap s <Nop>
   let @a = 's'
index 1b2a1886b081af74b3817c5f50feb330830ccfd4..410fe2aa59a22d3073172626e3e4ccdf4a7bc1b6 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4722,
 /**/
     4721,
 /**/