Skip to content

Commit e87edf3

Browse files
committed
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)
1 parent 561f8a5 commit e87edf3

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/edit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3656,7 +3656,9 @@ ins_compl_set_original_text(char_u *str)
36563656
{
36573657
char_u *p;
36583658

3659-
/* Replace the original text entry. */
3659+
/* Replace the original text entry.
3660+
* The ORIGINAL_TEXT flag is either at the first item or might possibly be
3661+
* at the last item for backward completion */
36603662
if (compl_first_match->cp_flags & ORIGINAL_TEXT) /* safety check */
36613663
{
36623664
p = vim_strsave(str);
@@ -3666,6 +3668,16 @@ ins_compl_set_original_text(char_u *str)
36663668
compl_first_match->cp_str = p;
36673669
}
36683670
}
3671+
else if (compl_first_match->cp_prev != NULL
3672+
&& (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT))
3673+
{
3674+
p = vim_strsave(str);
3675+
if (p != NULL)
3676+
{
3677+
vim_free(compl_first_match->cp_prev->cp_str);
3678+
compl_first_match->cp_prev->cp_str = p;
3679+
}
3680+
}
36693681
}
36703682

36713683
/*

src/testdir/test_popup.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,5 +814,14 @@ func Test_popup_command()
814814
call delete('Xtest')
815815
endfunc
816816

817+
func Test_popup_complete_backwards()
818+
new
819+
call setline(1, ['Post', 'Port', 'Po'])
820+
let expected=['Post', 'Port', 'Port']
821+
call cursor(3,2)
822+
call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<cr>", 'tx')
823+
call assert_equal(expected, getline(1,'$'))
824+
bwipe!
825+
endfunc
817826

818827
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1731,
765767
/**/
766768
1730,
767769
/**/

0 commit comments

Comments
 (0)