]> granicus.if.org Git - vim/commitdiff
patch 8.0.1806: InsertCharPre causes problems for autocomplete v8.0.1806
authorBram Moolenaar <Bram@vim.org>
Tue, 8 May 2018 20:48:00 +0000 (22:48 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 8 May 2018 20:48:00 +0000 (22:48 +0200)
Problem:    InsertCharPre causes problems for autocomplete. (Lifepillar)
Solution:   Check for InsertCharPre before calling vpeekc(). (Christian
            Brabandt, closes #2876)

src/edit.c
src/testdir/test_popup.vim
src/version.c

index eaf690ce9d49a6b0ad41604af8905a5deea87d7d..9b7206410ec674ecf1cb0442273f05d477a77361 100644 (file)
@@ -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];
index d682dd211047b84f65691beebc2d01079f39f196..89cdf0e8c1aefe3acd08e399441abe71c9b585ac 100644 (file)
@@ -831,4 +831,34 @@ func Test_popup_complete_backwards_ctrl_p()
   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("\<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
+
+
 " vim: shiftwidth=2 sts=2 expandtab
index b81046e61f6049b270a1793efd9464ccee6e0e50..5ebf7018486772c31e46e0c9b5e7ece91ce7071e 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1806,
 /**/
     1805,
 /**/