patch 9.1.1160: Ctrl-Y does not work well with "preinsert" when completing items
Problem: The 'preinsert' feature requires Ctrl-Y to confirm insertion,
but Ctrl-Y only works when the popup menu (pum) is displayed.
Without enforcing this dependency, it could lead to confusing
behavior or non-functional features.
Solution: Modify ins_compl_has_preinsert() to check for both 'menu' and
'menuone' flags when 'preinsert' is set. Update documentation
to clarify this requirement. This avoids adding complex
conditional behaviors. (glepnir)
fixes: #16728
closes: #16753
Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/edit.c b/src/edit.c
index 6f22b43..808aae1 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -146,7 +146,6 @@
#ifdef FEAT_CONCEAL
int cursor_line_was_concealed;
#endif
- int ins_completion = FALSE;
// Remember whether editing was restarted after CTRL-O.
did_restart_edit = restart_edit;
@@ -637,11 +636,8 @@
* and the cursor is still in the completed word. Only when there is
* a match, skip this when no matches were found.
*/
- ins_completion = ins_compl_active()
- && curwin->w_cursor.col >= ins_compl_col()
- && ins_compl_has_shown_match();
-
- if (ins_completion && pum_wanted())
+ if (ins_compl_active() && curwin->w_cursor.col >= ins_compl_col()
+ && ins_compl_has_shown_match() && pum_wanted())
{
// BS: Delete one character from "compl_leader".
if ((c == K_BS || c == Ctrl_H)
@@ -699,8 +695,6 @@
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
// it does fix up the text when finishing completion.
diff --git a/src/insexpand.c b/src/insexpand.c
index edc4265..8a6f8af 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -1985,12 +1985,15 @@
}
/*
- * Return TRUE when preinsert is set otherwise FALSE.
+ * Return TRUE when preinsert is set AND both 'menu' and 'menuone' flags
+ * are also set, otherwise return FALSE.
*/
static int
ins_compl_has_preinsert(void)
{
- return (get_cot_flags() & (COT_PREINSERT | COT_FUZZY)) == COT_PREINSERT;
+ int cur_cot_flags = get_cot_flags();
+ return (cur_cot_flags & (COT_PREINSERT | COT_FUZZY | COT_MENU | COT_MENUONE))
+ == (COT_PREINSERT | COT_MENU | COT_MENUONE);
}
/*
diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim
index b302a3e..e91a99e 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -3217,10 +3217,11 @@
call assert_equal("fobar", getline('.'))
call assert_equal(5, col('.'))
+ " When the pum is not visible, the preinsert has no effect
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('.'))
+ call assert_equal("foo1bar", getline('.'))
+ call assert_equal(7, col('.'))
bw!
set cot&
diff --git a/src/version.c b/src/version.c
index f29e1f3..12d4434 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1160,
+/**/
1159,
/**/
1158,