0
0
mirror of https://github.com/vim/vim.git synced 2025-07-25 10:54:51 -04:00

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 <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
glepnir 2025-02-20 22:13:24 +01:00 committed by Christian Brabandt
parent 4418041698
commit 52fd867f5e
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
3 changed files with 15 additions and 4 deletions

View File

@ -146,6 +146,7 @@ edit(
#ifdef FEAT_CONCEAL #ifdef FEAT_CONCEAL
int cursor_line_was_concealed; int cursor_line_was_concealed;
#endif #endif
int ins_completion = FALSE;
// Remember whether editing was restarted after CTRL-O. // Remember whether editing was restarted after CTRL-O.
did_restart_edit = restart_edit; did_restart_edit = restart_edit;
@ -636,10 +637,11 @@ edit(
* and the cursor is still in the completed word. Only when there is * and the cursor is still in the completed word. Only when there is
* a match, skip this when no matches were found. * a match, skip this when no matches were found.
*/ */
if (ins_compl_active() ins_completion = ins_compl_active()
&& pum_wanted() && curwin->w_cursor.col >= ins_compl_col()
&& curwin->w_cursor.col >= ins_compl_col() && ins_compl_has_shown_match();
&& ins_compl_has_shown_match())
if (ins_completion && pum_wanted())
{ {
// BS: Delete one character from "compl_leader". // BS: Delete one character from "compl_leader".
if ((c == K_BS || c == Ctrl_H) if ((c == K_BS || c == Ctrl_H)
@ -697,6 +699,8 @@ edit(
ins_compl_delete(); ins_compl_delete();
} }
} }
else if (ins_completion && !pum_wanted() && ins_compl_preinsert_effect())
ins_compl_delete();
// Prepare for or stop CTRL-X mode. This doesn't do completion, but // Prepare for or stop CTRL-X mode. This doesn't do completion, but
// it does fix up the text when finishing completion. // it does fix up the text when finishing completion.

View File

@ -3171,6 +3171,11 @@ function Test_completeopt_preinsert()
call assert_equal("fobar", getline('.')) call assert_equal("fobar", getline('.'))
call assert_equal(5, col('.')) call assert_equal(5, col('.'))
set cot=preinsert
call feedkeys("Sfoo1 foo2\<CR>f\<C-X>\<C-N>bar", 'tx')
call assert_equal("fbar", getline('.'))
call assert_equal(4, col('.'))
bw! bw!
set cot& set cot&
set omnifunc& set omnifunc&

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1127,
/**/ /**/
1126, 1126,
/**/ /**/