]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0473: Pasting ". register without autocommands breaks TextPut* v9.2.0473
authorzeertzjq <zeertzjq@outlook.com>
Mon, 11 May 2026 16:49:19 +0000 (16:49 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 11 May 2026 16:49:19 +0000 (16:49 +0000)
Problem:  Pasting ". register without TextPut* autocommands breaks
          subsequent TextPut* autocommands (after 9.2.0470).
Solution: Only decrement add_last_insert if it has been incremented
          (zeertzjq).

closes: #20192

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/register.c
src/testdir/test_autocmd.vim
src/version.c

index 44e6aba6f59ae08fee6b90f086291598aa37ab3e..86ac02cfc153797d8139db7eff073f9958b89cf7 100644 (file)
@@ -1736,7 +1736,8 @@ do_put(
            stuffcharReadbuff(VIsual_mode);
 
 #ifdef FEAT_EVAL
-       if (has_textputpre() || has_textputpost())
+       bool has_textput_events = has_textputpre() || has_textputpost();
+       if (has_textput_events)
            add_last_insert++;
 #endif
 
@@ -1748,11 +1749,10 @@ do_put(
        // TextPutPost after TextPutPre.
        if (has_textputpre())
            put_do_autocmd('.', NULL, NULL, false, dir);
-
        if (has_textputpost())
            put_do_autocmd('.', NULL, NULL, true, dir);
 
-       if (--add_last_insert == 0)
+       if (has_textput_events && --add_last_insert == 0)
            ga_clear(&last_insert_ga);
 #endif
 
index 2a3616893fbd04b4db4908fb4f39d489b2f9113a..ecd5791c9032153458f362532978c1bc66fda3a5 100644 (file)
@@ -6069,22 +6069,27 @@ func Test_TextPutX()
   au! TextPutPre
   let g:pre_event = []
 
-  " Test that recursive ". register calls have the same contents for post and
-  " pre
-  au TextPutPre * put . | let g:pre_event = copy(v:event)
-  au TextPutPost * let g:post_event = copy(v:event)
+  for round in range(2)
+    " Recursive ". register calls have the same contents for post and pre.
+    au TextPutPre * put . | let g:pre_event = copy(v:event)
+    au TextPutPost * let g:post_event = copy(v:event)
 
-  call feedkeys("iinserted\<Esc>", 'x')
-  norm! ".p
+    call feedkeys("iinserted\<Esc>", 'x')
+    norm! ".p
 
-  call assert_equal(
-        \ #{regcontents: ["inserted"], regname: '.',
-        \ operator: 'p', regtype: 'v', visual: v:false},
-        \ g:pre_event)
-  call assert_equal(g:pre_event, g:post_event)
+    call assert_equal(
+          \ #{regcontents: ["inserted"], regname: '.',
+          \ operator: 'p', regtype: 'v', visual: v:false},
+          \ g:pre_event)
+    call assert_equal(g:pre_event, g:post_event)
 
-  au! TextPutPre
-  au! TextPutPost
+    au! TextPutPre
+    au! TextPutPost
+
+    " Pasting ". register without TextPutPre/TextPutPost autocommands should
+    " not interfere with these autocommands in the next round.
+    norm! ".p
+  endfor
 
   unlet g:post_event
   unlet g:pre_event
index 3aff29a29625b7e51348fc090708e9fbafce3a0d..f96e170e4eeca0b4075bdd46ae692a846cc820d1 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    473,
 /**/
     472,
 /**/