]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1413: spurious CursorHold triggered in GUI on startup v9.1.1413
authorGary Johnson <garyjohn@spocom.com>
Mon, 26 May 2025 18:10:25 +0000 (20:10 +0200)
committerChristian Brabandt <cb@256bit.org>
Mon, 26 May 2025 18:10:25 +0000 (20:10 +0200)
Problem:  spurious CursorHold triggered in GUI on startup
Solution: init global did_cursorhold flag to true
          (Gary Johnson)

When Vim is started in GUI mode, the CursorHold autocommand event is
triggered 'updatetime' milliseconds later, even when the user has not
pressed a key.  This is different from the behavior of Vim in terminal
mode, which does not trigger a CursorHold autocommand event at startup,
and contradicts the description of the CursorHold event in ":help
CursorHold", which states that the event is "[n]ot triggered until the
user has pressed a key".

The fix is to change the initial value of did_cursorhold from FALSE to
TRUE.  While it is true that the CursorDone event has not been done yet
at startup, it should appear to have been done until the user presses
a key.

fixes #17350
closes: #17382

Signed-off-by: Gary Johnson <garyjohn@spocom.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/globals.h
src/testdir/test_gui.vim
src/version.c

index f143c8f90577793008e07a86d3622355f485cbba..38e9b8bbf5f40a02441d2004bd84c49dfa2fb46d 100644 (file)
@@ -1614,7 +1614,7 @@ EXTERN int        autocmd_bufnr INIT(= 0);     // fnum for <abuf> on cmdline
 EXTERN char_u  *autocmd_match INIT(= NULL); // name for <amatch> on cmdline
 EXTERN int     aucmd_cmdline_changed_count INIT(= 0);
 
-EXTERN int     did_cursorhold INIT(= FALSE); // set when CursorHold t'gerd
+EXTERN int     did_cursorhold INIT(= TRUE);  // set when CursorHold t'gerd
 EXTERN pos_T   last_cursormoved              // for CursorMoved event
 # ifdef DO_INIT
                    = {0, 0, 0}
index 9d319960bf5e2a0557dfb4b6175abd1f576c99e9..fc23db50f06db2b40b2aa95f3e8a1c1d902d9cea 100644 (file)
@@ -1747,4 +1747,26 @@ func Test_gui_csi_keytrans()
   call assert_equal('<C-D>', keytrans("\x9b\xfc\x04D"))
 endfunc
 
+" Test that CursorHold is NOT triggered at startup before a keypress
+func Test_CursorHold_not_triggered_at_startup()
+  defer delete('Xcursorhold.log')
+  defer delete('Xcursorhold_test.vim')
+  call writefile([
+        \ 'set updatetime=300',
+        \ 'let g:cursorhold_triggered = 0',
+        \ 'autocmd CursorHold * let g:cursorhold_triggered += 1 | call writefile(["CursorHold triggered"], "Xcursorhold.log", "a")',
+        \ 'call timer_start(400, {-> execute(''call writefile(["g:cursorhold_triggered=" . g:cursorhold_triggered], "Xcursorhold.log", "a") | qa!'')})',
+        \ ], 'Xcursorhold_test.vim')
+
+  let vimcmd = v:progpath . ' -g -f -N -u NONE -i NONE -S Xcursorhold_test.vim'
+  call system(vimcmd)
+
+  let lines = filereadable('Xcursorhold.log') ? readfile('Xcursorhold.log') : []
+
+  " Assert that CursorHold did NOT trigger at startup
+  call assert_false(index(lines, 'CursorHold triggered') != -1)
+  let found = filter(copy(lines), 'v:val =~ "^g:cursorhold_triggered="')
+  call assert_equal(['g:cursorhold_triggered=0'], found)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index ef919bdd8bb63eb29af9b056a8ce54c1fc6c5cf0..adb5654bcd17dcb1d949c6fb49d457c48dc465b6 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1413,
 /**/
     1412,
 /**/