# HG changeset patch # User Bram Moolenaar # Date 1649523602 -7200 # Node ID a0cd2b7a78efd685e5eba7fa2d3833a926669d0a # Parent c7353962787c7c65072e85770a9d5d295849d9c6 patch 8.2.4722: ending recording with mapping records too much Commit: https://github.com/vim/vim/commit/81b46a6ccd818609e1ca8cd410e26a58428c30ba Author: zeertzjq Date: Sat Apr 9 17:58:49 2022 +0100 patch 8.2.4722: ending recording with mapping records too much Problem: When a recording is ended with a mapped key that key is also recorded. Solution: Remember the previous last_recorded_len. (closes #10122) diff --git a/src/getchar.c b/src/getchar.c --- a/src/getchar.c +++ b/src/getchar.c @@ -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 diff --git a/src/testdir/test_registers.vim b/src/testdir/test_registers.vim --- a/src/testdir/test_registers.vim +++ b/src/testdir/test_registers.vim @@ -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 let @a = 's' diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4722, +/**/ 4721, /**/ 4720,