Skip to content

Commit 39de952

Browse files
committed
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)
1 parent 18cebf4 commit 39de952

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/edit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6185,6 +6185,8 @@ insertchar(
61856185
* 'paste' is set)..
61866186
* Don't do this when there an InsertCharPre autocommand is defined,
61876187
* because we need to fire the event for every character.
6188+
* Do the check for InsertCharPre before the call to vpeekc() because the
6189+
* InsertCharPre autocommand could change the input buffer.
61886190
*/
61896191
#ifdef USE_ON_FLY_SCROLL
61906192
dont_scroll = FALSE; /* allow scrolling here */
@@ -6194,6 +6196,7 @@ insertchar(
61946196
#ifdef FEAT_MBYTE
61956197
&& (!has_mbyte || (*mb_char2len)(c) == 1)
61966198
#endif
6199+
&& !has_insertcharpre()
61976200
&& vpeekc() != NUL
61986201
&& !(State & REPLACE_FLAG)
61996202
#ifdef FEAT_CINDENT
@@ -6202,7 +6205,7 @@ insertchar(
62026205
#ifdef FEAT_RIGHTLEFT
62036206
&& !p_ri
62046207
#endif
6205-
&& !has_insertcharpre())
6208+
)
62066209
{
62076210
#define INPUT_BUFLEN 100
62086211
char_u buf[INPUT_BUFLEN + 1];

src/testdir/test_popup.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,4 +831,34 @@ func Test_popup_complete_backwards_ctrl_p()
831831
bwipe!
832832
endfunc
833833

834+
fun! Test_complete_o_tab()
835+
let s:o_char_pressed = 0
836+
837+
fun! s:act_on_text_changed()
838+
if s:o_char_pressed
839+
let s:o_char_pressed = 0
840+
call feedkeys("\<c-x>\<c-n>", 'i')
841+
endif
842+
endf
843+
844+
set completeopt=menu,noselect
845+
new
846+
imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X"
847+
autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o')
848+
autocmd! TextChangedI <buffer> call <sid>act_on_text_changed()
849+
call setline(1, ['hoard', 'hoax', 'hoarse', ''])
850+
let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax']
851+
call cursor(4,1)
852+
call test_override("char_avail", 1)
853+
call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx')
854+
call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx')
855+
call assert_equal(l:expected, getline(1,'$'))
856+
857+
call test_override("char_avail", 0)
858+
bwipe!
859+
set completeopt&
860+
delfunc s:act_on_text_changed
861+
endf
862+
863+
834864
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1806,
764766
/**/
765767
1805,
766768
/**/

0 commit comments

Comments
 (0)