]> granicus.if.org Git - vim/commitdiff
patch 8.2.3768: timer_info() has the wrong repeat value in a timer callback v8.2.3768
authorBram Moolenaar <Bram@vim.org>
Thu, 9 Dec 2021 18:42:57 +0000 (18:42 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 Dec 2021 18:42:57 +0000 (18:42 +0000)
Problem:    timer_info() has the wrong repeat value in a timer callback.
Solution:   Do not add one to the repeat value when in the callback.
            (closes #9294)

src/testdir/test_timers.vim
src/time.c
src/version.c

index 865a03b6d023fd499c3885779ca4ac6ab2b63f8b..c833dd837f667a9a36eae7c9bcddc0db51aca7b9 100644 (file)
@@ -117,6 +117,13 @@ func Test_timer_info()
   call assert_equal([], timer_info(id))
 
   call assert_fails('call timer_info("abc")', 'E39:')
+
+  " check repeat count inside the callback
+  let g:timer_repeat = []
+  let tid = timer_start(10, {tid -> execute("call add(g:timer_repeat, timer_info(tid)[0].repeat)")}, #{repeat: 3})
+  sleep 100m
+  call assert_equal([2, 1, 0], g:timer_repeat)
+  unlet g:timer_repeat
 endfunc
 
 func Test_timer_stopall()
index 362fd46452e5c31b506e4c859bc4d95a27ed798d..bb4a2028293b1e59e2566789b4a38a7476b7266d 100644 (file)
@@ -696,7 +696,8 @@ add_timer_info(typval_T *rettv, timer_T *timer)
     dict_add_number(dict, "remaining", (long)remaining);
 
     dict_add_number(dict, "repeat",
-                   (long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1));
+           (long)(timer->tr_repeat < 0 ? -1
+                            : timer->tr_repeat + (timer->tr_firing ? 0 : 1)));
     dict_add_number(dict, "paused", (long)(timer->tr_paused));
 
     di = dictitem_alloc((char_u *)"callback");
index c3e34e4a9528b6753701522bcb8ead1a35ca4b8f..473b934430868ef11f89eee4cb2d1f9a1c3b7ad6 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3768,
 /**/
     3767,
 /**/