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

a658728918
This commit is contained in:
zeertzjq
2026-07-01 21:02:18 +08:00
parent 826ca0ccfe
commit cef0dcd54e
3 changed files with 17 additions and 3 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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("\<Esc>q", 't') })
call timer_start(300, { -> feedkeys("\<Esc>q", 't') })
call feedkeys("qaSf", 'tx!')
call assert_equal("Sf\<Esc>", @a)
" Delayed autocompletion still works when recording.
if !has('win32') || has('nvim')
call setline(1, 'foobar foofoo')
call timer_start(300, { -> feedkeys("\<Down>\<C-Y>\<Esc>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\<Down>\<C-Y>\<Esc>", @a)
endif
set autocomplete& autocompletedelay&
bwipe!
endfunc