# HG changeset patch # User Christian Brabandt # Date 1525813207 -7200 # Node ID 08370aad873d4753004235b7e818c624cbd535e9 # Parent 1bf780b9069a618338f07f4d70b63e63fcf16b08 patch 8.0.1806: InsertCharPre causes problems for autocomplete commit https://github.com/vim/vim/commit/39de95257714b76ccd845d081cff57830a79b488 Author: Bram Moolenaar Date: Tue May 8 22:48:00 2018 +0200 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 #2876) diff --git a/src/edit.c b/src/edit.c --- a/src/edit.c +++ b/src/edit.c @@ -6185,6 +6185,8 @@ 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. */ #ifdef USE_ON_FLY_SCROLL dont_scroll = FALSE; /* allow scrolling here */ @@ -6194,6 +6196,7 @@ insertchar( #ifdef FEAT_MBYTE && (!has_mbyte || (*mb_char2len)(c) == 1) #endif + && !has_insertcharpre() && vpeekc() != NUL && !(State & REPLACE_FLAG) #ifdef FEAT_CINDENT @@ -6202,7 +6205,7 @@ insertchar( #ifdef FEAT_RIGHTLEFT && !p_ri #endif - && !has_insertcharpre()) + ) { #define INPUT_BUFLEN 100 char_u buf[INPUT_BUFLEN + 1]; diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -831,4 +831,34 @@ func Test_popup_complete_backwards_ctrl_ bwipe! endfunc +fun! Test_complete_o_tab() + 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 + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1806, +/**/ 1805, /**/ 1804,