From bebd1f9f7629c6150e7eadcf0d33e9c90c81add2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 20 Nov 2018 20:15:30 -0500 Subject: vim-patch:8.0.1731: characters deleted on completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Characters deleted on completion. (Adrià Farrés) Solution: Also check the last item for the ORIGINAL_TEXT flag. (Christian Brabandt, closes vim/vim#1645) https://github.com/vim/vim/commit/e87edf3b85f607632e5431640071fdbc36b685b2 --- src/nvim/edit.c | 10 ++++++++-- src/nvim/testdir/test_popup.vim | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index d20660bfb9..451d19b8e3 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3127,10 +3127,16 @@ static void ins_compl_restart(void) */ static void ins_compl_set_original_text(char_u *str) { - /* Replace the original text entry. */ - if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */ + // Replace the original text entry. + // The ORIGINAL_TEXT flag is either at the first item or might possibly be + // at the last item for backward completion + if (compl_first_match->cp_flags & ORIGINAL_TEXT) { // safety check xfree(compl_first_match->cp_str); compl_first_match->cp_str = vim_strsave(str); + } else if (compl_first_match->cp_prev != NULL + && (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT)) { + xfree(compl_first_match->cp_prev->cp_str); + compl_first_match->cp_prev->cp_str = vim_strsave(str); } } diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index c9cd04018c..09dc3ba43f 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -571,6 +571,15 @@ func Test_completion_clear_candidate_list() bw! endfunc +func Test_popup_complete_backwards() + new + call setline(1, ['Post', 'Port', 'Po']) + let expected=['Post', 'Port', 'Port'] + call cursor(3,2) + call feedkeys("A\". repeat("\", 3). "rt\", 'tx') + call assert_equal(expected, getline(1,'$')) + bwipe! +endfunc func Test_popup_and_preview_autocommand() " This used to crash Vim -- cgit