changeset 13718:66b1d74be322 v8.0.1731

patch 8.0.1731: characters deleted on completion commit https://github.com/vim/vim/commit/e87edf3b85f607632e5431640071fdbc36b685b2 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 17 22:14:32 2018 +0200 patch 8.0.1731: characters deleted on completion Problem: Characters deleted on completion. (Adri? Farr?s) Solution: Also check the last item for the ORIGINAL_TEXT flag. (Christian Brabandt, closes #1645)
author Christian Brabandt <cb@256bit.org>
date Tue, 17 Apr 2018 22:15:08 +0200
parents 5ccca18a0dff
children fb1a9741c1c5
files src/edit.c src/testdir/test_popup.vim src/version.c
diffstat 3 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -3656,7 +3656,9 @@ ins_compl_set_original_text(char_u *str)
 {
     char_u	*p;
 
-    /* Replace the original text entry. */
+    /* 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 */
     {
 	p = vim_strsave(str);
@@ -3666,6 +3668,16 @@ ins_compl_set_original_text(char_u *str)
 	    compl_first_match->cp_str = p;
 	}
     }
+    else if (compl_first_match->cp_prev != NULL
+	    && (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT))
+    {
+       p = vim_strsave(str);
+       if (p != NULL)
+       {
+           vim_free(compl_first_match->cp_prev->cp_str);
+           compl_first_match->cp_prev->cp_str = p;
+       }
+    }
 }
 
 /*
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -814,5 +814,14 @@ func Test_popup_command()
   call delete('Xtest')
 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\<C-X>". repeat("\<C-P>", 3). "rt\<cr>", 'tx')
+  call assert_equal(expected, getline(1,'$'))
+  bwipe!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1731,
+/**/
     1730,
 /**/
     1729,