Skip to content

Commit 52fd867

Browse files
glepnirchrisbra
authored andcommitted
patch 9.1.1127: preinsert text is not cleaned up correctly
Problem: when 'completeopt' is set to preinsert the preinserted text is not cleared when adding new leader (Yee Cheng Chin) Solution: add a condition to delete preinsert text in edit function (glepnir) closes: #16672 Signed-off-by: glepnir <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 4418041 commit 52fd867

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/edit.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ edit(
146146
#ifdef FEAT_CONCEAL
147147
int cursor_line_was_concealed;
148148
#endif
149+
int ins_completion = FALSE;
149150

150151
// Remember whether editing was restarted after CTRL-O.
151152
did_restart_edit = restart_edit;
@@ -636,10 +637,11 @@ edit(
636637
* and the cursor is still in the completed word. Only when there is
637638
* a match, skip this when no matches were found.
638639
*/
639-
if (ins_compl_active()
640-
&& pum_wanted()
641-
&& curwin->w_cursor.col >= ins_compl_col()
642-
&& ins_compl_has_shown_match())
640+
ins_completion = ins_compl_active()
641+
&& curwin->w_cursor.col >= ins_compl_col()
642+
&& ins_compl_has_shown_match();
643+
644+
if (ins_completion && pum_wanted())
643645
{
644646
// BS: Delete one character from "compl_leader".
645647
if ((c == K_BS || c == Ctrl_H)
@@ -697,6 +699,8 @@ edit(
697699
ins_compl_delete();
698700
}
699701
}
702+
else if (ins_completion && !pum_wanted() && ins_compl_preinsert_effect())
703+
ins_compl_delete();
700704

701705
// Prepare for or stop CTRL-X mode. This doesn't do completion, but
702706
// it does fix up the text when finishing completion.

src/testdir/test_ins_complete.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,6 +3171,11 @@ function Test_completeopt_preinsert()
31713171
call assert_equal("fobar", getline('.'))
31723172
call assert_equal(5, col('.'))
31733173

3174+
set cot=preinsert
3175+
call feedkeys("Sfoo1 foo2\<CR>f\<C-X>\<C-N>bar", 'tx')
3176+
call assert_equal("fbar", getline('.'))
3177+
call assert_equal(4, col('.'))
3178+
31743179
bw!
31753180
set cot&
31763181
set omnifunc&

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1127,
707709
/**/
708710
1126,
709711
/**/

0 commit comments

Comments
 (0)