vim-patch:9.1.1413: spurious CursorHold triggered in GUI on startup (#34195)

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 vim/vim#17350
closes: vim/vim#17382

318ff9c362

Co-authored-by: Gary Johnson <garyjohn@spocom.com>
This commit is contained in:
zeertzjq
2025-05-27 09:16:46 +08:00
committed by GitHub
parent 8c5bd841ed
commit c4e52d604c
2 changed files with 10 additions and 1 deletions

View File

@@ -39,7 +39,7 @@ EXTERN char *autocmd_fname INIT( = NULL); ///< fname for <afile> on cmdlin
EXTERN bool autocmd_fname_full INIT( = false); ///< autocmd_fname is full path EXTERN bool autocmd_fname_full INIT( = false); ///< autocmd_fname is full path
EXTERN int autocmd_bufnr INIT( = 0); ///< fnum for <abuf> on cmdline EXTERN int autocmd_bufnr INIT( = 0); ///< fnum for <abuf> on cmdline
EXTERN char *autocmd_match INIT( = NULL); ///< name for <amatch> on cmdline EXTERN char *autocmd_match INIT( = NULL); ///< name for <amatch> on cmdline
EXTERN bool did_cursorhold INIT( = false); ///< set when CursorHold t'gerd EXTERN bool did_cursorhold INIT( = true); ///< set when CursorHold t'gerd
typedef struct { typedef struct {
win_T *auc_win; ///< Window used in aucmd_prepbuf(). When not NULL the win_T *auc_win; ///< Window used in aucmd_prepbuf(). When not NULL the

View File

@@ -69,6 +69,15 @@ describe('CursorHold', function()
sleep(10) sleep(10)
eq(1, api.nvim_get_var('cursorhold')) eq(1, api.nvim_get_var('cursorhold'))
end) end)
it('is not triggered after only K_EVENT on startup', function()
api.nvim_set_option_value('updatetime', 20, {})
sleep(50)
eq(0, api.nvim_get_var('cursorhold'))
feed('0')
sleep(50)
eq(1, api.nvim_get_var('cursorhold'))
end)
end) end)
describe('CursorHoldI', function() describe('CursorHoldI', function()