]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1820: completion: some issues with 'acl' v9.1.1820
authorGirish Palya <girishji@gmail.com>
Fri, 3 Oct 2025 08:28:38 +0000 (08:28 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 3 Oct 2025 08:28:38 +0000 (08:28 +0000)
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>
src/insexpand.c
src/testdir/dumps/Test_autocompletedelay_longest_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_autocompletedelay_longest_2.dump [new file with mode: 0644]
src/testdir/dumps/Test_autocompletedelay_longest_3.dump [new file with mode: 0644]
src/testdir/dumps/Test_autocompletedelay_longest_4.dump [new file with mode: 0644]
src/testdir/dumps/Test_autocompletedelay_preinsert_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_autocompletedelay_preinsert_2.dump [new file with mode: 0644]
src/testdir/test_ins_complete.vim
src/version.c

index 286fc0b472ba3a70f18de5e09f5e58cdd7f13489..c231aa41b8dc459b3ded5721fb15ef0d29f5581d 100644 (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,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 (file)
index 0000000..10a5079
--- /dev/null
@@ -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 (file)
index 0000000..19a83bf
--- /dev/null
@@ -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 (file)
index 0000000..52bda2c
--- /dev/null
@@ -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 (file)
index 0000000..09a8514
--- /dev/null
@@ -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 (file)
index 0000000..3b1bc4b
--- /dev/null
@@ -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 (file)
index 0000000..17252df
--- /dev/null
@@ -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| 
index e7346b8b581ac469287ded76cde18df7d70b1fce..b10e07433a18d47a61fe4dce8fa352f66b6b85f6 100644 (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
index 431536543aa5422c24155de4a4284b4031df7a34..773c66b1b63de87c1929b0981fb31b195d252df4 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1820,
 /**/
     1819,
 /**/