Skip to content

Commit a2c5559

Browse files
glepnirchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 3e2affc commit a2c5559

5 files changed

Lines changed: 40 additions & 39 deletions

File tree

runtime/doc/options.txt

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Feb 27
1+
*options.txt* For Vim version 9.1. Last change: 2025 Feb 28
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2120,6 +2120,17 @@ A jump table for the options with a short description can be found at |Q_op|.
21202120
A comma-separated list of options for Insert mode completion
21212121
|ins-completion|. The supported values are:
21222122

2123+
fuzzy Enable |fuzzy-matching| for completion candidates. This
2124+
allows for more flexible and intuitive matching, where
2125+
characters can be skipped and matches can be found even
2126+
if the exact sequence is not typed.
2127+
2128+
longest Only insert the longest common text of the matches. If
2129+
the menu is displayed you can use CTRL-L to add more
2130+
characters. Whether case is ignored depends on the kind
2131+
of completion. For buffer text the 'ignorecase' option is
2132+
used.
2133+
21232134
menu Use a popup menu to show the possible completions. The
21242135
menu is only shown when there is more than one match and
21252136
sufficient colors are available. |ins-completion-menu|
@@ -2128,15 +2139,17 @@ A jump table for the options with a short description can be found at |Q_op|.
21282139
Useful when there is additional information about the
21292140
match, e.g., what file it comes from.
21302141

2131-
longest Only insert the longest common text of the matches. If
2132-
the menu is displayed you can use CTRL-L to add more
2133-
characters. Whether case is ignored depends on the kind
2134-
of completion. For buffer text the 'ignorecase' option is
2135-
used.
2142+
noinsert Do not insert any text for a match until the user selects
2143+
a match from the menu. Only works in combination with
2144+
"menu" or "menuone". No effect if "longest" is present.
21362145

2137-
preview Show extra information about the currently selected
2138-
completion in the preview window. Only works in
2139-
combination with "menu" or "menuone".
2146+
noselect Same as "noinsert", except that no menu item is
2147+
pre-selected. If both "noinsert" and "noselect" are
2148+
present, "noselect" has precedence.
2149+
2150+
nosort Disable sorting of completion candidates based on fuzzy
2151+
scores when "fuzzy" is enabled. Candidates will appear
2152+
in their original order.
21402153

21412154
popup Show extra information about the currently selected
21422155
completion in a popup window. Only works in combination
@@ -2151,28 +2164,16 @@ A jump table for the options with a short description can be found at |Q_op|.
21512164
See the example at |complete-popuphidden|.
21522165
{only works when compiled with the |+textprop| feature}
21532166

2154-
noinsert Do not insert any text for a match until the user selects
2155-
a match from the menu. Only works in combination with
2156-
"menu" or "menuone". No effect if "longest" is present.
2157-
2158-
noselect Same as "noinsert", except that no menu item is
2159-
pre-selected. If both "noinsert" and "noselect" are
2160-
present, "noselect" has precedence.
2161-
2162-
fuzzy Enable |fuzzy-matching| for completion candidates. This
2163-
allows for more flexible and intuitive matching, where
2164-
characters can be skipped and matches can be found even
2165-
if the exact sequence is not typed.
2166-
2167-
nosort Disable sorting of completion candidates based on fuzzy
2168-
scores when "fuzzy" is enabled. Candidates will appear
2169-
in their original order.
2170-
21712167
preinsert
21722168
Preinsert the portion of the first candidate word that is
21732169
not part of the current completion leader and using the
21742170
|hl-ComplMatchIns| highlight group. Does not work when
2175-
"fuzzy" is also included.
2171+
"fuzzy" is set. Requires both "menu" and "menuone" to be
2172+
set.
2173+
2174+
preview Show extra information about the currently selected
2175+
completion in the preview window. Only works in
2176+
combination with "menu" or "menuone".
21762177

21772178
*'completepopup'* *'cpp'*
21782179
'completepopup' 'cpp' string (default empty)

src/edit.c

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

151150
// Remember whether editing was restarted after CTRL-O.
152151
did_restart_edit = restart_edit;
@@ -637,11 +636,8 @@ edit(
637636
* and the cursor is still in the completed word. Only when there is
638637
* a match, skip this when no matches were found.
639638
*/
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())
639+
if (ins_compl_active() && curwin->w_cursor.col >= ins_compl_col()
640+
&& ins_compl_has_shown_match() && pum_wanted())
645641
{
646642
// BS: Delete one character from "compl_leader".
647643
if ((c == K_BS || c == Ctrl_H)
@@ -699,8 +695,6 @@ edit(
699695
ins_compl_delete();
700696
}
701697
}
702-
else if (ins_completion && !pum_wanted() && ins_compl_preinsert_effect())
703-
ins_compl_delete();
704698

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

src/insexpand.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,12 +1985,15 @@ ins_compl_len(void)
19851985
}
19861986

19871987
/*
1988-
* Return TRUE when preinsert is set otherwise FALSE.
1988+
* Return TRUE when preinsert is set AND both 'menu' and 'menuone' flags
1989+
* are also set, otherwise return FALSE.
19891990
*/
19901991
static int
19911992
ins_compl_has_preinsert(void)
19921993
{
1993-
return (get_cot_flags() & (COT_PREINSERT | COT_FUZZY)) == COT_PREINSERT;
1994+
int cur_cot_flags = get_cot_flags();
1995+
return (cur_cot_flags & (COT_PREINSERT | COT_FUZZY | COT_MENU | COT_MENUONE))
1996+
== (COT_PREINSERT | COT_MENU | COT_MENUONE);
19941997
}
19951998

19961999
/*

src/testdir/test_ins_complete.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,10 +3217,11 @@ function Test_completeopt_preinsert()
32173217
call assert_equal("fobar", getline('.'))
32183218
call assert_equal(5, col('.'))
32193219

3220+
" When the pum is not visible, the preinsert has no effect
32203221
set cot=preinsert
32213222
call feedkeys("Sfoo1 foo2\<CR>f\<C-X>\<C-N>bar", 'tx')
3222-
call assert_equal("fbar", getline('.'))
3223-
call assert_equal(4, col('.'))
3223+
call assert_equal("foo1bar", getline('.'))
3224+
call assert_equal(7, col('.'))
32243225

32253226
bw!
32263227
set cot&

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+
1160,
707709
/**/
708710
1159,
709711
/**/

0 commit comments

Comments
 (0)