patch 9.1.1820: completion: some issues with 'acl'

Commit: 
https://github.com/vim/vim/commit/f77c187277c3fd2af7a48f8b15093a3e40ca95a0
Author: Girish Palya <[email protected]>
Date:   Fri Oct 3 08:28:38 2025 +0000

    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/insexpand.c b/src/insexpand.c
index 286fc0b47..c231aa41b 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -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,16 +6304,19 @@ ins_compl_next(
            // inserted.
            update_screen(0);
 
-       // display the updated popup menu
-       ins_compl_show_pum();
-#ifdef FEAT_GUI
-       if (gui.in_use)
+       if (!has_autocomplete_delay)
        {
-           // Show the cursor after the match, not after the redrawn text.
-           setcursor();
-           out_flush_cursor(FALSE, FALSE);
-       }
+           // display the updated popup menu
+           ins_compl_show_pum();
+#ifdef FEAT_GUI
+           if (gui.in_use)
+           {
+               // Show the cursor after the match, not after the redrawn text.
+               setcursor();
+               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;
diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_1.dump 
b/src/testdir/dumps/Test_autocompletedelay_longest_1.dump
new file mode 100644
index 000000000..10a50793c
--- /dev/null
+++ b/src/testdir/dumps/Test_autocompletedelay_longest_1.dump
@@ -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| 
diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_2.dump 
b/src/testdir/dumps/Test_autocompletedelay_longest_2.dump
new file mode 100644
index 000000000..19a83bfa7
--- /dev/null
+++ b/src/testdir/dumps/Test_autocompletedelay_longest_2.dump
@@ -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| 
diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_3.dump 
b/src/testdir/dumps/Test_autocompletedelay_longest_3.dump
new file mode 100644
index 000000000..52bda2c30
--- /dev/null
+++ b/src/testdir/dumps/Test_autocompletedelay_longest_3.dump
@@ -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| 
diff --git a/src/testdir/dumps/Test_autocompletedelay_longest_4.dump 
b/src/testdir/dumps/Test_autocompletedelay_longest_4.dump
new file mode 100644
index 000000000..09a8514da
--- /dev/null
+++ b/src/testdir/dumps/Test_autocompletedelay_longest_4.dump
@@ -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| 
diff --git a/src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump 
b/src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump
new file mode 100644
index 000000000..3b1bc4bbd
--- /dev/null
+++ b/src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump
@@ -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| 
diff --git a/src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump 
b/src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump
new file mode 100644
index 000000000..17252dfa3
--- /dev/null
+++ b/src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump
@@ -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| 
diff --git a/src/testdir/test_ins_complete.vim 
b/src/testdir/test_ins_complete.vim
index e7346b8b5..b10e07433 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 431536543..773c66b1b 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 */
+/**/
+    1820,
 /**/
     1819,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1v4bPU-008zEC-5b%40256bit.org.

Raspunde prin e-mail lui