]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1160: Ctrl-Y does not work well with "preinsert" when completing items v9.1.1160
authorglepnir <glephunter@gmail.com>
Fri, 28 Feb 2025 16:43:42 +0000 (17:43 +0100)
committerChristian Brabandt <cb@256bit.org>
Fri, 28 Feb 2025 16:43:42 +0000 (17:43 +0100)
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>
runtime/doc/options.txt
src/edit.c
src/insexpand.c
src/testdir/test_ins_complete.vim
src/version.c

index cbd532262f25a7adbdf3ef411ce19131baca322e..48b4b599ae34fad1624baf25a6e5e52accecd97b 100644 (file)
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 9.1.  Last change: 2025 Feb 27
+*options.txt*  For Vim version 9.1.  Last change: 2025 Feb 28
 
 
                  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|.
        A comma-separated list of options for Insert mode completion
        |ins-completion|.  The supported values are:
 
+          fuzzy    Enable |fuzzy-matching| for completion candidates. This
+                   allows for more flexible and intuitive matching, where
+                   characters can be skipped and matches can be found even
+                   if the exact sequence is not typed.
+
+          longest  Only insert the longest common text of the matches.  If
+                   the menu is displayed you can use CTRL-L to add more
+                   characters.  Whether case is ignored depends on the kind
+                   of completion.  For buffer text the 'ignorecase' option is
+                   used.
+
           menu     Use a popup menu to show the possible completions.  The
                    menu is only shown when there is more than one match and
                    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|.
                    Useful when there is additional information about the
                    match, e.g., what file it comes from.
 
-          longest  Only insert the longest common text of the matches.  If
-                   the menu is displayed you can use CTRL-L to add more
-                   characters.  Whether case is ignored depends on the kind
-                   of completion.  For buffer text the 'ignorecase' option is
-                   used.
+          noinsert Do not insert any text for a match until the user selects
+                   a match from the menu. Only works in combination with
+                   "menu" or "menuone". No effect if "longest" is present.
 
-          preview  Show extra information about the currently selected
-                   completion in the preview window.  Only works in
-                   combination with "menu" or "menuone".
+          noselect Same as "noinsert", except that no menu item is
+                   pre-selected. If both "noinsert" and "noselect" are
+                   present, "noselect" has precedence.
+
+          nosort   Disable sorting of completion candidates based on fuzzy
+                   scores when "fuzzy" is enabled. Candidates will appear
+                   in their original order.
 
           popup    Show extra information about the currently selected
                    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|.
                    See the example at |complete-popuphidden|.
                    {only works when compiled with the |+textprop| feature}
 
-          noinsert Do not insert any text for a match until the user selects
-                   a match from the menu. Only works in combination with
-                   "menu" or "menuone". No effect if "longest" is present.
-
-          noselect Same as "noinsert", except that no menu item is
-                   pre-selected. If both "noinsert" and "noselect" are
-                   present, "noselect" has precedence.
-
-          fuzzy    Enable |fuzzy-matching| for completion candidates. This
-                   allows for more flexible and intuitive matching, where
-                   characters can be skipped and matches can be found even
-                   if the exact sequence is not typed.
-
-          nosort   Disable sorting of completion candidates based on fuzzy
-                   scores when "fuzzy" is enabled. Candidates will appear
-                   in their original order.
-
           preinsert
                    Preinsert the portion of the first candidate word that is
                    not part of the current completion leader and using the
                    |hl-ComplMatchIns| highlight group. Does not work when
-                   "fuzzy" is also included.
+                   "fuzzy" is set. Requires both "menu" and "menuone" to be
+                   set.
+
+          preview  Show extra information about the currently selected
+                   completion in the preview window.  Only works in
+                   combination with "menu" or "menuone".
 
                                        *'completepopup'* *'cpp'*
 'completepopup' 'cpp'  string (default empty)
index 6f22b43115159d4895a931cc70fba85be914bfb3..808aae1416b6c245142fb134b08d2ec113460a1b 100644 (file)
@@ -146,7 +146,6 @@ edit(
 #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 @@ edit(
         * 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 @@ edit(
                    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.
index edc4265e438cbef6a3aa836d07e08ca04b93b834..8a6f8afd8f31ed03c206fbd9bc131ddfcfb842d5 100644 (file)
@@ -1985,12 +1985,15 @@ ins_compl_len(void)
 }
 
 /*
- * 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);
 }
 
 /*
index b302a3ee745e7b03f30b49fed59fd59b6820df3d..e91a99e7cbb7e3394c3be1abead0b1a37878c2bc 100644 (file)
@@ -3217,10 +3217,11 @@ function Test_completeopt_preinsert()
   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&
index f29e1f3eb0c92d343b65e15638f8121b8b769a53..12d4434ec12a7e49c9b22734eb3cf3063aba9d93 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1160,
 /**/
     1159,
 /**/