vim-patch:9.1.1810: completion: "longest" doesn't work for manual completion with 'ac'

Problem:  completion: "longest" doesn't work for manual completion when
          'autocomplete' is on (after 9.1.1800).
Solution: Only reset compl_get_longest when enabling autocompletion
          (zeertzjq).

closes: vim/vim#18430

b3966d6a8e
This commit is contained in:
zeertzjq
2025-09-30 09:11:07 +08:00
parent f30a33858f
commit 756e55dc49
2 changed files with 23 additions and 4 deletions

View File

@@ -2266,7 +2266,11 @@ static void ins_compl_new_leader(void)
// Matches were cleared, need to search for them now. // Matches were cleared, need to search for them now.
// Set "compl_restarting" to avoid that the first match is inserted. // Set "compl_restarting" to avoid that the first match is inserted.
compl_restarting = true; compl_restarting = true;
compl_autocomplete = ins_compl_has_autocomplete(); if (ins_compl_has_autocomplete()) {
ins_compl_enable_autocomplete();
} else {
compl_autocomplete = false;
}
if (ins_complete(Ctrl_N, true) == FAIL) { if (ins_complete(Ctrl_N, true) == FAIL) {
compl_cont_status = 0; compl_cont_status = 0;
} }
@@ -2736,8 +2740,7 @@ bool ins_compl_prep(int c)
// Set "compl_get_longest" when finding the first matches. // Set "compl_get_longest" when finding the first matches.
if (ctrl_x_mode_not_defined_yet() if (ctrl_x_mode_not_defined_yet()
|| (ctrl_x_mode_normal() && !compl_started)) { || (ctrl_x_mode_normal() && !compl_started)) {
compl_get_longest = (get_cot_flags() & kOptCotFlagLongest) != 0 compl_get_longest = (get_cot_flags() & kOptCotFlagLongest) != 0;
&& !ins_compl_has_autocomplete();
compl_used_match = true; compl_used_match = true;
} }
@@ -6293,6 +6296,7 @@ int ins_complete(int c, bool enable_pum)
void ins_compl_enable_autocomplete(void) void ins_compl_enable_autocomplete(void)
{ {
compl_autocomplete = true; compl_autocomplete = true;
compl_get_longest = false;
} }
/// Remove (if needed) and show the popup menu /// Remove (if needed) and show the popup menu

View File

@@ -5984,7 +5984,7 @@ func Test_autocomplete_longest()
call feedkeys("Go\<ESC>", 'tx') call feedkeys("Go\<ESC>", 'tx')
call DoTest("f\<C-N>\<C-N>\<BS>\<BS>\<BS>\<BS>", 'foo', 3) call DoTest("f\<C-N>\<C-N>\<BS>\<BS>\<BS>\<BS>", 'foo', 3)
" Issue #18410: When both 'preinsert' and 'longest' are set, 'preinsert' " Issue #18410: When both "preinsert" and "longest" are set, "preinsert"
" takes precedence " takes precedence
%delete %delete
set autocomplete completeopt+=longest,preinsert set autocomplete completeopt+=longest,preinsert
@@ -6035,6 +6035,21 @@ func Test_autocomplete_longest()
%delete _ %delete _
delfunc CheckUndo delfunc CheckUndo
" Check that behavior of "longest" in manual completion is unchanged.
for ac in [v:false, v:true]
let &ac = ac
set completeopt=menuone,longest
call feedkeys("Ssign u\<C-X>\<C-V>", 'tx')
call assert_equal('sign un', getline('.'))
call feedkeys("Ssign u\<C-X>\<C-V>\<C-V>", 'tx')
call assert_equal('sign undefine', getline('.'))
call feedkeys("Ssign u\<C-X>\<C-V>\<C-V>\<C-V>", 'tx')
call assert_equal('sign unplace', getline('.'))
call feedkeys("Ssign u\<C-X>\<C-V>\<C-V>\<C-V>\<C-V>", 'tx')
call assert_equal('sign u', getline('.'))
%delete
endfor
bw! bw!
set cot& autocomplete& set cot& autocomplete&
delfunc GetLine delfunc GetLine