neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit c4e52d604c9ac2fd47ab176ef0d1e4d72015485b
parent 8c5bd841edffd5b02b04220ab85ae0e3b7c81953
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue, 27 May 2025 09:16:46 +0800

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

https://github.com/vim/vim/commit/318ff9c3627f595905064d11b0d66b63bfe89ff1

Co-authored-by: Gary Johnson <garyjohn@spocom.com>
Diffstat:
Msrc/nvim/autocmd.h | 2+-
Mtest/functional/autocmd/cursorhold_spec.lua | 9+++++++++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/nvim/autocmd.h b/src/nvim/autocmd.h @@ -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 int autocmd_bufnr INIT( = 0); ///< fnum for <abuf> 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 { win_T *auc_win; ///< Window used in aucmd_prepbuf(). When not NULL the diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua @@ -69,6 +69,15 @@ describe('CursorHold', function() sleep(10) eq(1, api.nvim_get_var('cursorhold')) 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) describe('CursorHoldI', function()