]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1762: completion: selected item not cleared on <BS> with 'ac' v9.1.1762
authorGirish Palya <girishji@gmail.com>
Mon, 15 Sep 2025 19:01:01 +0000 (19:01 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 15 Sep 2025 19:04:20 +0000 (19:04 +0000)
Problem:  completion: selected item not cleared on backspace when
          'autocomplete' is set
Solution: Clear the selected item (Girish Palya)

closes: #18260

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/insert.txt
src/insexpand.c
src/testdir/test_ins_complete.vim
src/version.c

index 0453b6f70d86521be84b53446582c83d3d2bbc99..c5991dc4ffe021a1b609291b4df00bab38fdb401 100644 (file)
@@ -1,4 +1,4 @@
-*insert.txt*    For Vim version 9.1.  Last change: 2025 Sep 11
+*insert.txt*    For Vim version 9.1.  Last change: 2025 Sep 15
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1437,6 +1437,8 @@ In the first state these keys have a special meaning:
 <BS> and CTRL-H   Delete one character, find the matches for the word before
                  the cursor.  This reduces the list of matches, often to one
                  entry, and switches to the second state.
+                 When 'autocomplete' is set, clears the selected item in the
+                 menu.
 Any non-special character:
                  Stop completion without changing the match and insert the
                  typed character.
@@ -1444,6 +1446,8 @@ Any non-special character:
 In the second and third state these keys have a special meaning:
 <BS> and CTRL-H   Delete one character, find the matches for the shorter word
                  before the cursor.  This may find more matches.
+                 When 'autocomplete' is set, clears the selected item in the
+                 menu.
 CTRL-L           Add one character from the current match, may reduce the
                  number of matches.
 any printable, non-white character:
index dac3698cf797fc107b4b108657aadbfbccd61882..c92ebf540e3f11f13bb8dec567bc7276c08ed77e 100644 (file)
@@ -2424,6 +2424,10 @@ ins_compl_bs(void)
        return K_BS;
     }
 
+    // Clear selection if a menu item is currently selected in autocompletion
+    if (compl_autocomplete && compl_first_match)
+       compl_shown_match = compl_first_match;
+
     ins_compl_new_leader();
     if (compl_shown_match != NULL)
        // Make sure current match is not a hidden item.
index a5e7a8b81c350539f3152d613973ebceab667ec7..559ffbe8b1fce3aa2ddcd12488bbd75a30231bd7 100644 (file)
@@ -5247,6 +5247,21 @@ func Test_autocomplete_trigger()
   call feedkeys("Sazx\<Left>\<BS>\<F2>\<Esc>0", 'tx!')
   call assert_equal(['and', 'afoo'], b:matches->mapnew('v:val.word'))
 
+  " Test 6: <BS> should clear the selected item
+  %d
+  call setline(1, ["foobarfoo", "foobar", "foobarbaz"])
+  call feedkeys("Gofo\<C-N>\<C-N>\<F2>\<F3>\<Esc>0", 'tx!')
+  call assert_equal(['foobarbaz', 'foobar', 'foobarfoo'], b:matches->mapnew('v:val.word'))
+  call assert_equal(1, b:selected)
+  call feedkeys("Sfo\<C-N>\<C-N>\<BS>\<F2>\<F3>\<Esc>0", 'tx!')
+  call assert_equal(['foobarbaz', 'foobar', 'foobarfoo'], b:matches->mapnew('v:val.word'))
+  call assert_equal(-1, b:selected)
+  call assert_equal('fooba', getline(4))
+  call feedkeys("Sfo\<C-N>\<C-N>\<BS>\<C-N>\<F2>\<F3>\<Esc>0", 'tx!')
+  call assert_equal(['foobarbaz', 'foobar', 'foobarfoo'], b:matches->mapnew('v:val.word'))
+  call assert_equal(0, b:selected)
+  call assert_equal('foobarbaz', getline(4))
+
   bw!
   call test_override("char_avail", 0)
   delfunc NonKeywordComplete
index 96a41c2d776a8115e40177c65203e7de900cadc0..9e722ac3ff615725f4d6cbd93a39798270b716ed 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1762,
 /**/
     1761,
 /**/