From f3d0d089074c4517b26ea3d2253eaae36c6212eb Mon Sep 17 00:00:00 2001 From: Girish Palya Date: Sun, 5 Oct 2025 13:14:10 +0000 Subject: [PATCH] patch 9.1.1827: completion: v9.1.1797 broke Ctrl-Y behaviour 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 Signed-off-by: Christian Brabandt --- src/edit.c | 7 +++++-- src/insexpand.c | 9 +++++++++ src/proto/insexpand.pro | 1 + src/testdir/test_ins_complete.vim | 21 +++++++++++++++++++++ src/version.c | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/edit.c b/src/edit.c index d564e2c9e6..c544df46f9 100644 --- a/src/edit.c +++ b/src/edit.c @@ -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()) diff --git a/src/insexpand.c b/src/insexpand.c index 38b2095632..40ba818668 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -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. diff --git a/src/proto/insexpand.pro b/src/proto/insexpand.pro index 31d1ccb351..bff291171f 100644 --- a/src/proto/insexpand.pro +++ b/src/proto/insexpand.pro @@ -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 : */ diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim index c2465030dd..a340d476e6 100644 --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -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\\\", 'tx') + call assert_equal('func1', getline('.')) + + set completeopt+=longest autocomplete + call feedkeys("Sf\\", 'tx') + call assert_equal('func2', getline('.')) + call feedkeys("Sf\", 'tx') + call assert_equal('func', getline('.')) + + set completeopt& autocomplete& + bw! + call test_override("char_avail", 0) +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable diff --git a/src/version.c b/src/version.c index 6680030645..81368c1c9e 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1827, /**/ 1826, /**/