From 02f126a2758e834a7e9dfbae0ede48bf8b90512f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 2 Sep 2019 16:44:08 -0400 Subject: 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) https://github.com/vim/vim/commit/39de95257714b76ccd845d081cff57830a79b488 --- src/nvim/edit.c | 6 ++++-- src/nvim/testdir/test_popup.vim | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ca64cc091d..16c4882975 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -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; diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 162df4b76e..53df30bb19 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -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("\\", 'i') + endif + endf + + set completeopt=menu,noselect + new + imap pumvisible() ? "\" : "X" + autocmd! InsertCharPre let s:o_char_pressed = (v:char ==# 'o') + autocmd! TextChangedI call 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\\\\", 'tx') + call feedkeys("oho\\\\", '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 =complete_info().mode -- cgit