Skip to content

Commit f77c187

Browse files
girishjichrisbra
authored andcommitted
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>
1 parent 1a691af commit f77c187

9 files changed

+128
-11
lines changed

src/insexpand.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,7 +5104,7 @@ get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos)
51045104
ptr = ins_compl_get_next_word_or_line(st->ins_buf,
51055105
st->cur_match_pos, &len, &cont_s_ipos);
51065106
if (ptr == NULL || (ins_compl_has_preinsert()
5107-
&& STRCMP(ptr, compl_pattern.string) == 0))
5107+
&& STRCMP(ptr, ins_compl_leader()) == 0))
51085108
continue;
51095109

51105110
if (is_nearest_active() && in_curbuf)
@@ -6222,6 +6222,7 @@ ins_compl_next(
62226222
|| (compl_autocomplete && !ins_compl_has_preinsert());
62236223
int compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0;
62246224
int compl_preinsert = ins_compl_has_preinsert();
6225+
int has_autocomplete_delay = (compl_autocomplete && p_acl > 0);
62256226

62266227
// When user complete function return -1 for findstart which is next
62276228
// time of 'always', compl_shown_match become NULL.
@@ -6265,7 +6266,11 @@ ins_compl_next(
62656266

62666267
// Insert the text of the new completion, or the compl_leader.
62676268
if (!started && ins_compl_preinsert_longest())
6269+
{
62686270
ins_compl_insert(TRUE, TRUE);
6271+
if (has_autocomplete_delay)
6272+
update_screen(0); // Show the inserted text right away
6273+
}
62696274
else if (compl_no_insert && !started && !compl_preinsert)
62706275
{
62716276
ins_compl_insert_bytes(compl_orig_text.string + get_compl_len(), -1);
@@ -6291,24 +6296,27 @@ ins_compl_next(
62916296
// may undisplay the popup menu first
62926297
ins_compl_upd_pum();
62936298

6294-
if (pum_enough_matches())
6299+
if (pum_enough_matches() && !has_autocomplete_delay)
62956300
// Will display the popup menu, don't redraw yet to avoid flicker.
62966301
pum_call_update_screen();
62976302
else
62986303
// Not showing the popup menu yet, redraw to show the user what was
62996304
// inserted.
63006305
update_screen(0);
63016306

6302-
// display the updated popup menu
6303-
ins_compl_show_pum();
6304-
#ifdef FEAT_GUI
6305-
if (gui.in_use)
6307+
if (!has_autocomplete_delay)
63066308
{
6307-
// Show the cursor after the match, not after the redrawn text.
6308-
setcursor();
6309-
out_flush_cursor(FALSE, FALSE);
6310-
}
6309+
// display the updated popup menu
6310+
ins_compl_show_pum();
6311+
#ifdef FEAT_GUI
6312+
if (gui.in_use)
6313+
{
6314+
// Show the cursor after the match, not after the redrawn text.
6315+
setcursor();
6316+
out_flush_cursor(FALSE, FALSE);
6317+
}
63116318
#endif
6319+
}
63126320

63136321
// Delete old text to be replaced, since we're still searching and
63146322
// don't want to match ourselves!
@@ -7362,6 +7370,12 @@ ins_complete(int c, int enable_pum)
73627370
{
73637371
if (char_avail())
73647372
{
7373+
if (ins_compl_preinsert_effect()
7374+
&& ins_compl_win_active(curwin))
7375+
{
7376+
ins_compl_delete(); // Remove pre-inserted text
7377+
compl_ins_end_col = compl_col;
7378+
}
73657379
ins_compl_restart();
73667380
compl_interrupted = TRUE;
73677381
break;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
2+
|a|u|t|o|c|o|m|x@2| @64
3+
|a|u|t|o|c>o+0#00e0003&|m| +0#0000000&@67
4+
|~+0#4040ff13&| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
2+
|a|u|t|o|c|o|m|x@2| @64
3+
|a|u|t|o|c>o+0#00e0003&|m| +0#0000000&@67
4+
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59
5+
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
2+
|a|u|t|o|c|o|m|x@2| @64
3+
|a|u>t+0#00e0003&|o|c|o|m| +0#0000000&@67
4+
|~+0#4040ff13&| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
2+
|a|u|t|o|c|o|m|x@2| @64
3+
|a|u>t+0#00e0003&|o|c|o|m| +0#0000000&@67
4+
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59
5+
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
2+
|a|u|t|o|c|o|m|x@2| @64
3+
|a|u>t+0#00e0003&|o|c|o|m|p|l|e|t|e| +0#0000000&@62
4+
|~+0#4040ff13&| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0|u|t|o|c|o|m|p|l|e|t|e| @62
2+
|a|u|t|o|c|o|m|x@2| @64
3+
|a|u>t+0#00e0003&|o|c|o|m|p|l|e|t|e| +0#0000000&@62
4+
|a+0#0000001#e0e0e08|u|t|o|c|o|m|p|l|e|t|e| @2| +0#4040ff13#ffffff0@59
5+
|a+0#0000001#ffd7ff255|u|t|o|c|o|m|x@2| @4| +0#4040ff13#ffffff0@59
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|1| @10|A|l@1|

src/testdir/test_ins_complete.vim

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5756,7 +5756,7 @@ func Test_autocomplete_longest()
57565756
call test_override("char_avail", 1)
57575757
new
57585758
inoremap <buffer><F5> <C-R>=GetLine()<CR>
5759-
set completeopt=longest autocomplete
5759+
set completeopt+=longest autocomplete
57605760
call setline(1, ["foobar", "foozbar"])
57615761
call feedkeys("Go\<ESC>", 'tx')
57625762

@@ -5996,4 +5996,45 @@ func Test_refresh_always_with_fuzzy()
59965996
call test_override("char_avail", 0)
59975997
endfunc
59985998

5999+
func Test_autocompletedelay_longest_preinsert()
6000+
CheckScreendump
6001+
let lines =<< trim [SCRIPT]
6002+
call setline(1, ['autocomplete', 'autocomxxx'])
6003+
set autocomplete completeopt+=longest autocompletedelay=500
6004+
[SCRIPT]
6005+
call writefile(lines, 'XTest_autocompletedelay', 'D')
6006+
let buf = RunVimInTerminal('-S XTest_autocompletedelay', {'rows': 10})
6007+
6008+
" No spurious characters when autocompletedelay is in effect
6009+
call term_sendkeys(buf, "Goau")
6010+
sleep 10m
6011+
call term_sendkeys(buf, "toc")
6012+
sleep 100m
6013+
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_1', {})
6014+
sleep 500m
6015+
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_2', {})
6016+
6017+
" Deleting a char should still show longest text
6018+
call term_sendkeys(buf, "\<Esc>Saut")
6019+
sleep 10m
6020+
call term_sendkeys(buf, "\<BS>")
6021+
sleep 100m
6022+
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_3', {})
6023+
sleep 500m
6024+
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_4', {})
6025+
6026+
" Preinsert
6027+
call term_sendkeys(buf, "\<Esc>:set completeopt& completeopt+=preinsert\<CR>")
6028+
6029+
" Show preinserted text right away but display popup later
6030+
call term_sendkeys(buf, "\<Esc>Sau")
6031+
sleep 100m
6032+
call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_1', {})
6033+
sleep 500m
6034+
call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_2', {})
6035+
6036+
call term_sendkeys(buf, "\<esc>")
6037+
call StopVimInTerminal(buf)
6038+
endfunc
6039+
59996040
" vim: shiftwidth=2 sts=2 expandtab nofoldenable

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ static char *(features[]) =
729729

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1820,
732734
/**/
733735
1819,
734736
/**/

0 commit comments

Comments
 (0)