diff --git a/src/nvim/register.c b/src/nvim/register.c index 6cbee49d2a..23bbff0831 100644 --- a/src/nvim/register.c +++ b/src/nvim/register.c @@ -23,6 +23,7 @@ #include "nvim/getchar.h" #include "nvim/globals.h" #include "nvim/indent.h" +#include "nvim/insexpand.h" #include "nvim/keycodes.h" #include "nvim/mark.h" #include "nvim/mbyte.h" @@ -1301,6 +1302,11 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) const pos_T orig_end = curbuf->b_op_end; unsigned cur_ve_flags = get_ve_flags(curwin); + // Remove any preinserted text (issue vim/vim#19329) + if (ins_compl_preinsert_effect()) { + ins_compl_delete(false); + } + curbuf->b_op_start = curwin->w_cursor; // default for '[ mark curbuf->b_op_end = curwin->w_cursor; // default for '] mark diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index f844f44a2c..78810f64f4 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -6378,4 +6378,26 @@ func Test_autocomplete_preinsert_null_leader() delfunc GetState endfunc +" Issue #19329: When register contents are inserted, remove preinserted text +func Test_ins_register_preinsert_autocomplete() + func TestOmni(findstart, base) + if a:findstart + return col(".") - 1 + endif + return ["foo", "foobar"] + endfunc + + call Ntest_override("char_avail", 1) + new + set omnifunc=TestOmni complete^=o + set completeopt=preinsert autocomplete + + call feedkeys("ifoo \\=\"xyz\"\\", 'tx') + call assert_equal("foo xyz", getline('.')) + bw! + set omnifunc& complete& completeopt& autocomplete& + call Ntest_override("char_avail", 0) + delfunc TestOmni +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable