From cef0dcd54e1f6bec12ea2fdd3a3bbe03845999e0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Jul 2026 21:02:18 +0800 Subject: [PATCH] vim-patch:9.2.0755: 'autocomplete' behaves inconsistently when recording Problem: If 'autocompletedelay' is non-zero, 'autocomplete' doesn't work when recording a register (after 9.2.0750). Solution: Still produce K_COMPLETE_DELAY when recording a register, and drop it in gotchars_add_byte() instead (zeertzjq). This patch only changes the behavior when recording a register. Replaying a register with 'autocomplete' still doesn't fully work regardless of 'autocompletedelay', as 'autocomplete' isn't triggered when there is pending input. closes: vim/vim#20675 https://github.com/vim/vim/commit/a658728918405294e134fbc81f13b50311924db5 --- src/nvim/getchar.c | 4 ++++ src/nvim/os/input.c | 4 ++-- test/old/testdir/test_ins_complete.vim | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index c90d8b418c..025f48d001 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1194,6 +1194,10 @@ static bool gotchars_add_byte(gotchars_state_T *state, uint8_t byte) goto ret_false; } c = TO_SPECIAL(state->prev_c, c); + // Drop K_COMPLETE_DELAY, it's not useful in a recording. + if (c == K_COMPLETE_DELAY) { + state->buflen = 0; + } } // When receiving a multibyte character, store it until we have all // the bytes, so that it won't be split between two buffer blocks, diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 84475d4443..29aa6d0cad 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -150,9 +150,9 @@ int input_get(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e // 'autocompletedelay' and 'updatetime' so the delay does not postpone // CursorHold. Once CursorHold has fired, only the delay is left. // Gate the injection like trigger_cursorhold() so the deferred key - // cannot fire while recording or outside Insert mode. + // cannot fire while outside Insert mode, but do still fire the key + // when recording a register (gotchars_add_byte() will ignore it). bool delay_pending = ins_compl_autocomplete_pending() && p_acl > 0 - && reg_recording == 0 && typebuf.tb_len == 0 && !ins_compl_active() && (get_real_state() & MODE_INSERT) != 0; diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index d5b60c789d..72e2a11f1a 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -6124,10 +6124,20 @@ func Test_autocompletedelay_no_record() let @a = '' " Type a char that arms the delay, idle past 'autocompletedelay' so a " K_COMPLETE_DELAY would be injected, then end Insert mode and stop recording. - call timer_start(200, { -> feedkeys("\q", 't') }) + call timer_start(300, { -> feedkeys("\q", 't') }) call feedkeys("qaSf", 'tx!') call assert_equal("Sf\", @a) + " Delayed autocompletion still works when recording. + if !has('win32') || has('nvim') + call setline(1, 'foobar foofoo') + call timer_start(300, { -> feedkeys("\\\q", 't') }) + call feedkeys("qaof", 'tx!') + call assert_equal('foobar', getline('.')) + " XXX: This doesn't produce the same result when replaying. + call assert_equal("of\\\", @a) + endif + set autocomplete& autocompletedelay& bwipe! endfunc