0
0
mirror of https://github.com/vim/vim.git synced 2025-10-16 07:24:23 -04:00

patch 9.1.1820: completion: some issues with 'acl'

Problem:  completion: some issues with 'acl' when "preinsert" and
          "longest" is in 'completeopt' (musonius, after v9.1.1638)
Solution: Fix various issues (see details below) (Girish Palya)

This commit addresses multiple issues in the 'autocompletedelay' behavior with
"preinsert" and "longest":

- Prevents spurious characters from being inserted.
- Ensures the completion menu is not shown until `autocompletedelay` has
  expired.
- Shows the "preinsert" effect immediately.
- Keeps the "preinsert" effect visible even when a character is deleted.

fixes: #18443
closes: #18460

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Girish Palya
2025-10-03 08:28:38 +00:00
committed by Christian Brabandt
parent 1a691afd27
commit f77c187277
9 changed files with 128 additions and 11 deletions

View File

@@ -5104,7 +5104,7 @@ get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos)
ptr = ins_compl_get_next_word_or_line(st->ins_buf,
st->cur_match_pos, &len, &cont_s_ipos);
if (ptr == NULL || (ins_compl_has_preinsert()
&& STRCMP(ptr, compl_pattern.string) == 0))
&& STRCMP(ptr, ins_compl_leader()) == 0))
continue;
if (is_nearest_active() && in_curbuf)
@@ -6222,6 +6222,7 @@ ins_compl_next(
|| (compl_autocomplete && !ins_compl_has_preinsert());
int compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0;
int compl_preinsert = ins_compl_has_preinsert();
int has_autocomplete_delay = (compl_autocomplete && p_acl > 0);
// When user complete function return -1 for findstart which is next
// time of 'always', compl_shown_match become NULL.
@@ -6265,7 +6266,11 @@ ins_compl_next(
// Insert the text of the new completion, or the compl_leader.
if (!started && ins_compl_preinsert_longest())
{
ins_compl_insert(TRUE, TRUE);
if (has_autocomplete_delay)
update_screen(0); // Show the inserted text right away
}
else if (compl_no_insert && !started && !compl_preinsert)
{
ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
@@ -6291,7 +6296,7 @@ ins_compl_next(
// may undisplay the popup menu first
ins_compl_upd_pum();
if (pum_enough_matches())
if (pum_enough_matches() && !has_autocomplete_delay)
// Will display the popup menu, don't redraw yet to avoid flicker.
pum_call_update_screen();
else
@@ -6299,6 +6304,8 @@ ins_compl_next(
// inserted.
update_screen(0);
if (!has_autocomplete_delay)
{
// display the updated popup menu
ins_compl_show_pum();
#ifdef FEAT_GUI
@@ -6309,6 +6316,7 @@ ins_compl_next(
out_flush_cursor(FALSE, FALSE);
}
#endif
}
// Delete old text to be replaced, since we're still searching and
// don't want to match ourselves!
@@ -7362,6 +7370,12 @@ ins_complete(int c, int enable_pum)
{
if (char_avail())
{
if (ins_compl_preinsert_effect()
&& ins_compl_win_active(curwin))
{
ins_compl_delete(); // Remove pre-inserted text
compl_ins_end_col = compl_col;
}
ins_compl_restart();
compl_interrupted = TRUE;
break;

View File

@@ -0,0 +1,10 @@
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
|a|u|t|o|c|o|m|x@2| @64
|a|u|t|o|c>o+0#00e0003&|m| +0#0000000&@67
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|T|o|p|

View File

@@ -0,0 +1,10 @@
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
|a|u|t|o|c|o|m|x@2| @64
|a|u|t|o|c>o+0#00e0003&|m| +0#0000000&@67
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|T|o|p|

View File

@@ -0,0 +1,10 @@
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
|a|u|t|o|c|o|m|x@2| @64
|a|u>t+0#00e0003&|o|c|o|m| +0#0000000&@67
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|

View File

@@ -0,0 +1,10 @@
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
|a|u|t|o|c|o|m|x@2| @64
|a|u>t+0#00e0003&|o|c|o|m| +0#0000000&@67
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|

View File

@@ -0,0 +1,10 @@
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
|a|u|t|o|c|o|m|x@2| @64
|a|u>t+0#00e0003&|o|c|o|m|p|l|e|t|e| +0#0000000&@62
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|

View File

@@ -0,0 +1,10 @@
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
|a|u|t|o|c|o|m|x@2| @64
|a|u>t+0#00e0003&|o|c|o|m|p|l|e|t|e| +0#0000000&@62
|a+0#0000001#e0e0e08|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|

View File

@@ -5756,7 +5756,7 @@ func Test_autocomplete_longest()
call test_override("char_avail", 1)
new
inoremap <buffer><F5> <C-R>=GetLine()<CR>
set completeopt=longest autocomplete
set completeopt+=longest autocomplete
call setline(1, ["foobar", "foozbar"])
call feedkeys("Go\<ESC>", 'tx')
@@ -5996,4 +5996,45 @@ func Test_refresh_always_with_fuzzy()
call test_override("char_avail", 0)
endfunc
func Test_autocompletedelay_longest_preinsert()
CheckScreendump
let lines =<< trim [SCRIPT]
call setline(1, ['autocomplete', 'autocomxxx'])
set autocomplete completeopt+=longest autocompletedelay=500
[SCRIPT]
call writefile(lines, 'XTest_autocompletedelay', 'D')
let buf = RunVimInTerminal('-S XTest_autocompletedelay', {'rows': 10})
" No spurious characters when autocompletedelay is in effect
call term_sendkeys(buf, "Goau")
sleep 10m
call term_sendkeys(buf, "toc")
sleep 100m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_1', {})
sleep 500m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_2', {})
" Deleting a char should still show longest text
call term_sendkeys(buf, "\<Esc>Saut")
sleep 10m
call term_sendkeys(buf, "\<BS>")
sleep 100m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_3', {})
sleep 500m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_4', {})
" Preinsert
call term_sendkeys(buf, "\<Esc>:set completeopt& completeopt+=preinsert\<CR>")
" Show preinserted text right away but display popup later
call term_sendkeys(buf, "\<Esc>Sau")
sleep 100m
call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_1', {})
sleep 500m
call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_2', {})
call term_sendkeys(buf, "\<esc>")
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab nofoldenable

View File

@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1820,
/**/
1819,
/**/