]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1374: completion: 'smartcase' not respected when filtering matches v9.1.1374
authorGirish Palya <girishji@gmail.com>
Thu, 8 May 2025 21:28:52 +0000 (23:28 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 8 May 2025 21:28:52 +0000 (23:28 +0200)
Problem:  Currently, 'smartcase' is respected when completing keywords
          using <C-N>, <C-P>, <C-X><C-N>, and <C-X><C-P>. However, when
          a user continues typing and the completion menu is filtered
          using cached matches, 'smartcase' is not applied. This leads
          to poor-quality or irrelevant completion suggestions, as shown
          in the example below.
Solution: When filtering cached completion items after typing additional
          characters, apply case-sensitive comparison if 'smartcase' is
          enabled and the typed pattern includes uppercase characters.
          This ensures consistent and expected completion behavior.
          (Girish Palya)

closes: #17271

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

index f52cf40adb27ce872c940ca95f617fbbd98345f3..f3d92b290b7815c52cfb876cae48672f68c9a726 100644 (file)
@@ -1,4 +1,4 @@
-*insert.txt*    For Vim version 9.1.  Last change: 2025 Apr 14
+*insert.txt*    For Vim version 9.1.  Last change: 2025 May 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1347,6 +1347,7 @@ use all space available.
 The 'pumwidth' option can be used to set a minimum width.  The default is 15
 characters.
 
+                                                       *compl-states*
 There are three states:
 1. A complete match has been inserted, e.g., after using CTRL-N or CTRL-P.
 2. A cursor key has been used to select another match.  The match was not
index bed14abb13e0c7f9c8fad0c0486eaf039d62f83f..f3824cdbf3d6ff2b51c8aed6ee3bb456f65ad635 100644 (file)
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 9.1.  Last change: 2025 May 07
+*options.txt*  For Vim version 9.1.  Last change: 2025 May 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -7742,9 +7742,11 @@ A jump table for the options with a short description can be found at |Q_op|.
        Override the 'ignorecase' option if the search pattern contains upper
        case characters.  Only used when the search pattern is typed and
        'ignorecase' option is on.  Used for the commands "/", "?", "n", "N",
-       ":g" and ":s".  Not used for "*", "#", "gd", tag search, etc.  After
-       "*" and "#" you can make 'smartcase' used by doing a "/" command,
-       recalling the search pattern from history and hitting <Enter>.
+       ":g" and ":s" and when filtering matches for the completion menu
+       |compl-states|.
+       Not used for "*", "#", "gd", tag search, etc.  After "*" and "#" you
+       can make 'smartcase' used by doing a "/" command, recalling the search
+       pattern from history and hitting <Enter>.
        NOTE: This option is reset when 'compatible' is set.
 
                             *'smartindent'* *'si'* *'nosmartindent'* *'nosi'*
index bb0558dab0ee925d22fddcd768156eb3f99892df..ae80f0e6df0947ee77e612edacaf04ca4c4de83a 100644 (file)
@@ -6645,6 +6645,7 @@ compl-keyword     insert.txt      /*compl-keyword*
 compl-omni     insert.txt      /*compl-omni*
 compl-omni-filetypes   insert.txt      /*compl-omni-filetypes*
 compl-spelling insert.txt      /*compl-spelling*
+compl-states   insert.txt      /*compl-states*
 compl-stop     insert.txt      /*compl-stop*
 compl-tag      insert.txt      /*compl-tag*
 compl-thesaurus        insert.txt      /*compl-thesaurus*
index afa800d86d74fc24ad04e6ca318385f0a9c0fd0d..371e4b314b2bfc37198ed43d6278badd224e4991 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2025 May 07
+*version9.txt*  For Vim version 9.1.  Last change: 2025 May 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41626,6 +41626,7 @@ Completion: ~
   "{flag}^<limit>" notation
 - add ":filetype" command completion
 - add "filetypecmd" completion type for |getcompletion()|
+- 'smartcase' applies to completion filtering
 
 Options: ~
 - the default for 'commentstring' contains whitespace padding to have
index 3839586dbb728cfc4ea382322f5cf21320d96e68..7bbff4ecb4fccff850dbf5eb8c5ec4acb13602f4 100644 (file)
@@ -1507,7 +1507,7 @@ ins_compl_build_pum(void)
                match_count = 1;
                max_matches_found = FALSE;
            }
-           else if (cpt_sources_array && !max_matches_found)
+           else if (cpt_sources_array != NULL && !max_matches_found)
            {
                int max_matches = cpt_sources_array[cur_source].max_matches;
                if (max_matches > 0 && match_count > max_matches)
@@ -1515,10 +1515,16 @@ ins_compl_build_pum(void)
            }
        }
 
+       // Apply 'smartcase' behavior during normal mode
+       if (ctrl_x_mode_normal() && !p_inf && compl_leader.string
+               && !ignorecase(compl_leader.string) && !fuzzy_filter)
+           compl->cp_flags &= ~CP_ICASE;
+
        if (!match_at_original_text(compl)
                && !max_matches_found
                && (compl_leader.string == NULL
-                   || ins_compl_equal(compl, compl_leader.string, (int)compl_leader.length)
+                   || ins_compl_equal(compl, compl_leader.string,
+                       (int)compl_leader.length)
                    || (fuzzy_filter && compl->cp_score > 0)))
        {
            ++compl_match_arraysize;
index 5222a433dfba7dd9b21a04f46289c7b3037a83e5..ea7e65492e22ffed3200275e2bc5cdf867b3cd4a 100644 (file)
@@ -439,7 +439,7 @@ ignorecase(char_u *pat)
 }
 
 /*
- * As ignorecase() put pass the "ic" and "scs" flags.
+ * As ignorecase() but pass the "ic" and "scs" flags.
  */
     int
 ignorecase_opt(char_u *pat, int ic_in, int scs)
index 73565a56e276524e89c6025c40bedbd149f8083d..6f342ae46695ce4987c3e81a9ef6cfa9f65e60e1 100644 (file)
@@ -4213,6 +4213,93 @@ func Test_complete_append_selected_match_default()
   delfunc PrintMenuWords
 endfunc
 
+" Test normal mode (^N/^P/^X^N/^X^P) with smartcase when 1) matches are first
+" found and 2) matches are filtered (when a character is typed).
+func Test_smartcase_normal_mode()
+
+  func! PrintMenu()
+    let info = complete_info(["matches"])
+    call map(info.matches, {_, v -> v.word})
+    return info
+  endfunc
+
+  func! TestInner(key)
+    let pr = "\<c-r>=PrintMenu()\<cr>"
+
+    new
+    set completeopt=menuone,noselect ignorecase smartcase
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}{pr}"
+    call assert_equal('F{''matches'': [''Fast'', ''FAST'', ''False'',
+          \ ''FALSE'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}a{pr}"
+    call assert_equal('Fa{''matches'': [''Fast'', ''False'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}a\<bs>{pr}"
+    call assert_equal('F{''matches'': [''Fast'', ''FAST'', ''False'',
+          \ ''FALSE'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}ax{pr}"
+    call assert_equal('Fax{''matches'': []}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}ax\<bs>{pr}"
+    call assert_equal('Fa{''matches'': [''Fast'', ''False'']}', getline(1))
+
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}A{pr}"
+    call assert_equal('FA{''matches'': [''FAST'', ''FALSE'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}A\<bs>{pr}"
+    call assert_equal('F{''matches'': [''Fast'', ''FAST'', ''False'',
+          \ ''FALSE'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}AL{pr}"
+    call assert_equal('FAL{''matches'': [''FALSE'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}ALx{pr}"
+    call assert_equal('FALx{''matches'': []}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOF{a:key}ALx\<bs>{pr}"
+    call assert_equal('FAL{''matches'': [''FALSE'']}', getline(1))
+
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOf{a:key}{pr}"
+    call assert_equal('f{''matches'': [''Fast'', ''FAST'', ''False'', ''FALSE'',
+          \ ''fast'', ''false'']}', getline(1))
+    %d
+    call setline(1, ["Fast", "FAST", "False", "FALSE", "fast", "false"])
+    exe $"normal! ggOf{a:key}a{pr}"
+    call assert_equal('fa{''matches'': [''Fast'', ''FAST'', ''False'', ''FALSE'',
+          \ ''fast'', ''false'']}', getline(1))
+
+    %d
+    exe $"normal! ggOf{a:key}{pr}"
+    call assert_equal('f{''matches'': []}', getline(1))
+    exe $"normal! ggOf{a:key}a\<bs>{pr}"
+    call assert_equal('f{''matches'': []}', getline(1))
+    set ignorecase& smartcase& completeopt&
+    bw!
+  endfunc
+
+  call TestInner("\<c-n>")
+  call TestInner("\<c-p>")
+  call TestInner("\<c-x>\<c-n>")
+  call TestInner("\<c-x>\<c-p>")
+  delfunc PrintMenu
+  delfunc TestInner
+endfunc
+
 " Test 'nearest' flag of 'completeopt'
 func Test_nearest_cpt_option()
 
index 5b85a2bbdf3338083af02cf0a62b142535e90fbc..236306eb2103493220228bbf8bd10ff041877258 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1374,
 /**/
     1373,
 /**/