diff options
-rw-r--r-- | src/nvim/os/input.c | 3 | ||||
-rw-r--r-- | test/functional/autocmd/cursorhold_spec.lua | 19 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 8fc4a5dce5..fc7390a303 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -133,7 +133,7 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } } else { uint64_t wait_start = os_hrtime(); - assert((int)p_ut >= cursorhold_time); + cursorhold_time = MIN(cursorhold_time, (int)p_ut); if ((result = inbuf_poll((int)p_ut - cursorhold_time, events)) == kInputNone) { if (read_stream.closed && silent_mode) { // Drained eventloop & initial input; exit silent/batch-mode (-es/-Es). @@ -148,7 +148,6 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } } else { cursorhold_time += (int)((os_hrtime() - wait_start) / 1000000); - cursorhold_time = MIN(cursorhold_time, (int)p_ut); } } diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index 5d54610e1d..b04bd5233a 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local eval = helpers.eval local feed = helpers.feed local retry = helpers.retry local exec = helpers.source @@ -12,13 +11,16 @@ local meths = helpers.meths before_each(clear) describe('CursorHold', function() - it('is triggered correctly #12587', function() + before_each(function() exec([[ + let g:cursorhold = 0 augroup test au CursorHold * let g:cursorhold += 1 augroup END ]]) + end) + it('is triggered correctly #12587', function() local function test_cursorhold(fn, early) local ut = 2 -- if testing with small 'updatetime' fails, double its value and test again @@ -47,6 +49,17 @@ describe('CursorHold', function() test_cursorhold(function() feed('<Ignore>') end, 0) test_cursorhold(function() meths.feedkeys(ignore_key, 'n', true) end, 0) end) + + it("reducing 'updatetime' while waiting for CursorHold #20241", function() + meths.set_option('updatetime', 10000) + feed('0') -- reset did_cursorhold + meths.set_var('cursorhold', 0) + sleep(50) + eq(0, meths.get_var('cursorhold')) + meths.set_option('updatetime', 20) + sleep(10) + eq(1, meths.get_var('cursorhold')) + end) end) describe('CursorHoldI', function() @@ -64,7 +77,7 @@ describe('CursorHoldI', function() feed('ifoo') retry(5, nil, function() sleep(1) - eq(1, eval('g:cursorhold')) + eq(1, meths.get_var('cursorhold')) end) end) end) |