vim-patch:8.0.1806: InsertCharPre causes problems for autocomplete

Problem:    InsertCharPre causes problems for autocomplete. (Lifepillar)
Solution:   Check for InsertCharPre before calling vpeekc(). (Christian
            Brabandt, closes vim/vim#2876)
39de952577
This commit is contained in:
Jan Edmund Lazo
2019-09-02 16:44:08 -04:00
parent 07b209b1fe
commit 02f126a275
2 changed files with 34 additions and 2 deletions

View File

@@ -5541,13 +5541,15 @@ insertchar (
// 'paste' is set)..
// Don't do this when there an InsertCharPre autocommand is defined,
// because we need to fire the event for every character.
// Do the check for InsertCharPre before the call to vpeekc() because the
// InsertCharPre autocommand could change the input buffer.
if (!ISSPECIAL(c)
&& (!has_mbyte || (*mb_char2len)(c) == 1)
&& !has_event(EVENT_INSERTCHARPRE)
&& vpeekc() != NUL
&& !(State & REPLACE_FLAG)
&& !cindent_on()
&& !p_ri
&& !has_event(EVENT_INSERTCHARPRE)) {
&& !p_ri) {
#define INPUT_BUFLEN 100
char_u buf[INPUT_BUFLEN + 1];
int i;

View File

@@ -746,6 +746,36 @@ func Test_popup_complete_backwards()
bwipe!
endfunc
fun! Test_complete_o_tab()
throw 'skipped: Nvim does not support test_override()'
let s:o_char_pressed = 0
fun! s:act_on_text_changed()
if s:o_char_pressed
let s:o_char_pressed = 0
call feedkeys("\<c-x>\<c-n>", 'i')
endif
endf
set completeopt=menu,noselect
new
imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X"
autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o')
autocmd! TextChangedI <buffer> call <sid>act_on_text_changed()
call setline(1, ['hoard', 'hoax', 'hoarse', ''])
let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax']
call cursor(4,1)
call test_override("char_avail", 1)
call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx')
call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx')
call assert_equal(l:expected, getline(1,'$'))
call test_override("char_avail", 0)
bwipe!
set completeopt&
delfunc s:act_on_text_changed
endf
func Test_popup_complete_info_01()
new
inoremap <buffer><F5> <C-R>=complete_info().mode<CR>