]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1827: completion: v9.1.1797 broke Ctrl-Y behaviour v9.1.1827
authorGirish Palya <girishji@gmail.com>
Sun, 5 Oct 2025 13:14:10 +0000 (13:14 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 5 Oct 2025 13:14:10 +0000 (13:14 +0000)
Problem:  completion: v9.1.1797 broke Ctrl-Y behaviour
          (ddad431, after v9.1.1797)
Solution: Restore correct behaviour (Girish Palya).

closes: #18494

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/edit.c
src/insexpand.c
src/proto/insexpand.pro
src/testdir/test_ins_complete.vim
src/version.c

index d564e2c9e6bb9b2b6e525633f230d3aef3ea321d..c544df46f90154da01ae22111a1190bfe7f3b3d7 100644 (file)
@@ -693,12 +693,15 @@ edit(
                        && stop_arrow() == OK)
                {
                    ins_compl_delete();
-                   ins_compl_insert(FALSE, !ins_compl_has_preinsert());
-                   if (ins_compl_preinsert_longest())
+                   if (ins_compl_preinsert_longest()
+                           && !ins_compl_is_match_selected())
                    {
+                       ins_compl_insert(FALSE, TRUE);
                        ins_compl_init_get_longest();
                        continue;
                    }
+                   else
+                       ins_compl_insert(FALSE, FALSE);
                }
                // Delete preinserted text when typing special chars
                else if (IS_WHITE_NL_OR_NUL(c) && ins_compl_preinsert_effect())
index 38b2095632a488562d67c739b4948cee7b7cff47..40ba818668517eb6a4e621bda8e04d02aa674d92 100644 (file)
@@ -853,6 +853,15 @@ is_nearest_active(void)
        && !(flags & COT_FUZZY);
 }
 
+/*
+ * TRUE if a match is selected (even if it is not inserted).
+ */
+    int
+ins_compl_is_match_selected(void)
+{
+    return compl_shown_match != NULL && !is_first_match(compl_shown_match);
+}
+
 /*
  * Returns TRUE if autocomplete is active and the pre-insert effect targets the
  * longest prefix.
index 31d1ccb3518386b84771fcfafa1c0d3762930fa3..bff291171fcf48360b1b638c1e3b48526dd8521e 100644 (file)
@@ -77,4 +77,5 @@ int ins_complete(int c, int enable_pum);
 void ins_compl_enable_autocomplete(void);
 void free_insexpand_stuff(void);
 void f_preinserted(typval_T *argvars, typval_T *rettv);
+int ins_compl_is_match_selected(void);
 /* vim: set ft=c : */
index c2465030dd49089ba6364a367130a8292a41d3de..a340d476e673e1715c0f07a1c884f9cb260c4f76 100644 (file)
@@ -6036,4 +6036,25 @@ func Test_autocompletedelay_longest_preinsert()
   call StopVimInTerminal(buf)
 endfunc
 
+" Issue 18493
+func Test_longest_preinsert_accept()
+  call test_override("char_avail", 1)
+  new
+  call setline(1, ['func1', 'xfunc', 'func2'])
+  set completeopt+=noselect
+
+  call feedkeys("Gof\<C-N>\<Down>\<C-Y>", 'tx')
+  call assert_equal('func1', getline('.'))
+
+  set completeopt+=longest autocomplete
+  call feedkeys("Sf\<Down>\<C-Y>", 'tx')
+  call assert_equal('func2', getline('.'))
+  call feedkeys("Sf\<C-Y>", 'tx')
+  call assert_equal('func', getline('.'))
+
+  set completeopt& autocomplete&
+  bw!
+  call test_override("char_avail", 0)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
index 66800306457ca6ef9a53da1fd2e511f0da054e5f..81368c1c9e93b9509c8543c20033cb5296cc6384 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1827,
 /**/
     1826,
 /**/