aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTomas Slusny <slusnucky@gmail.com>2025-03-03 17:51:42 +0100
committerzeertzjq <zeertzjq@outlook.com>2025-03-04 06:20:20 +0800
commit99d688e6459c7963b00a95d544de7a3de951a70b (patch)
treee984f5121dddf2fbf462c31a3d1a7941482ed119 /test
parent948179cb19c75a9e79cdf2c86c441304c5285e81 (diff)
downloadrneovim-99d688e6459c7963b00a95d544de7a3de951a70b.tar.gz
rneovim-99d688e6459c7963b00a95d544de7a3de951a70b.tar.bz2
rneovim-99d688e6459c7963b00a95d544de7a3de951a70b.zip
vim-patch:9.1.1166: command-line auto-completion hard with wildmenu
Problem: command-line auto-completion hard with wildmenu Solution: implement "noselect" wildoption value (Girish Palya) When `noselect` is present in `wildmode` and 'wildmenu' is enabled, the completion menu appears without pre-selecting the first item. This change makes it easier to implement command-line auto-completion, where the menu dynamically appears as characters are typed, and `<Tab>` can be used to manually select an item. This can be achieved by leveraging the `CmdlineChanged` event to insert `wildchar(m)`, triggering completion menu. Without this change, auto-completion using the 'wildmenu' mechanism is not feasible, as it automatically inserts the first match, preventing dynamic selection. The following Vimscript snippet demonstrates how to configure auto-completion using `noselect`: ```vim vim9script set wim=noselect:lastused,full wop=pum wcm=<C-@> wmnu autocmd CmdlineChanged : timer_start(0, function(CmdComplete, [getcmdline()])) def CmdComplete(cur_cmdline: string, timer: number) var [cmdline, curpos] = [getcmdline(), getcmdpos()] if cur_cmdline ==# cmdline # Avoid completing each character in keymaps and pasted text && !pumvisible() && curpos == cmdline->len() + 1 if cmdline[curpos - 2] =~ '[\w*/:]' # Reduce noise by completing only selected characters feedkeys("\<C-@>", "ti") set eventignore+=CmdlineChanged # Suppress redundant completion attempts timer_start(0, (_) => { getcmdline()->substitute('\%x00$', '', '')->setcmdline() # Remove <C-@> if no completion items exist set eventignore-=CmdlineChanged }) endif endif enddef ``` fixes: vim/vim#16551 closes: vim/vim#16759 https://github.com/vim/vim/commit/2bacc3e5fb3569e0fd98e129cb1e422ca18b80a6 Cherry-pick Wildmode_Tests() change from patch 9.0.0418. Co-authored-by: Girish Palya <girishji@gmail.com> Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/old/testdir/gen_opt_test.vim1
-rw-r--r--test/old/testdir/test_cmdline.vim61
2 files changed, 56 insertions, 6 deletions
diff --git a/test/old/testdir/gen_opt_test.vim b/test/old/testdir/gen_opt_test.vim
index 64876ce318..d1d27cf578 100644
--- a/test/old/testdir/gen_opt_test.vim
+++ b/test/old/testdir/gen_opt_test.vim
@@ -352,6 +352,7 @@ let test_values = {
\ 'bs'],
\ ['xxx']],
\ 'wildmode': [['', 'full', 'longest', 'list', 'lastused', 'list:full',
+ \ 'noselect', 'noselect,full', 'noselect:lastused,full',
\ 'full,longest', 'full,full,full,full'],
\ ['xxx', 'a4', 'full,full,full,full,full']],
\ 'wildoptions': [['', 'tagfile', 'pum', 'fuzzy'], ['xxx']],
diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim
index d4ad63d43e..d9496ba2a6 100644
--- a/test/old/testdir/test_cmdline.vim
+++ b/test/old/testdir/test_cmdline.vim
@@ -2168,22 +2168,58 @@ func Wildmode_tests()
call assert_equal('AAA AAAA AAAAA', g:Sline)
call assert_equal('"b A', @:)
+ " When 'wildmenu' is not set, 'noselect' completes first item
+ set wildmode=noselect
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+
+ " When 'noselect' is present, do not complete first <tab>.
+ set wildmenu
+ set wildmode=noselect
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+
+ " When 'full' is present, complete after first <tab>.
+ set wildmode=noselect,full
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+ call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneB', @:)
+ call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneB', @:)
+
+ " 'noselect' has no effect when 'longest' is present.
+ set wildmode=noselect:longest
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd one', @:)
+
+ " Complete 'noselect' value in 'wildmode' option
+ set wildmode&
+ call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"set wildmode=noselect', @:)
+ call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"set wildmode=noselect', @:)
+
" when using longest completion match, matches shorter than the argument
" should be ignored (happens with :help)
set wildmode=longest,full
- set wildmenu
call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
call assert_equal('"help a', @:)
" non existing file
call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
call assert_equal('"e a1b2y3z4', @:)
- set wildmenu&
" Test for longest file name completion with 'fileignorecase'
" On MS-Windows, file names are case insensitive.
if has('unix')
- call writefile([], 'XTESTfoo')
- call writefile([], 'Xtestbar')
+ call writefile([], 'XTESTfoo', 'D')
+ call writefile([], 'Xtestbar', 'D')
set nofileignorecase
call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"e XTESTfoo', @:)
@@ -2195,10 +2231,23 @@ func Wildmode_tests()
call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"e Xtest', @:)
set fileignorecase&
- call delete('XTESTfoo')
- call delete('Xtestbar')
endif
+ " If 'noselect' is present, single item menu should not insert item
+ func! T(a, c, p)
+ return "oneA"
+ endfunc
+ command! -nargs=1 -complete=custom,T MyCmd
+ set wildmode=noselect,full
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+ " 'nowildmenu' should make 'noselect' ineffective
+ set nowildmenu
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+
%argdelete
delcommand MyCmd
delfunc T