Skip to content

Commit 094dd15

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.1636: expanding a pattern interferes with cmdline completion
Problem: Expanding a pattern interferes with command line completion. Solution: Set the file index only when appropriate. (closes vim#12519)
1 parent da51ad5 commit 094dd15

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

src/cmdexpand.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ ExpandOne(
957957
int mode)
958958
{
959959
char_u *ss = NULL;
960-
static int findex;
960+
static int findex; // TODO: Move into expand_T
961961
static char_u *orig_save = NULL; // kept value of orig
962962
int orig_saved = FALSE;
963963
int i;
@@ -971,8 +971,9 @@ ExpandOne(
971971
if (mode == WILD_CANCEL)
972972
ss = vim_strsave(orig_save ? orig_save : (char_u *)"");
973973
else if (mode == WILD_APPLY)
974-
ss = vim_strsave(findex == -1 ? (orig_save ?
975-
orig_save : (char_u *)"") : xp->xp_files[findex]);
974+
ss = vim_strsave(findex == -1
975+
? (orig_save ? orig_save : (char_u *)"")
976+
: xp->xp_files[findex]);
976977

977978
// free old names
978979
if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
@@ -985,7 +986,9 @@ ExpandOne(
985986
if (compl_match_array != NULL)
986987
cmdline_pum_remove();
987988
}
988-
findex = 0;
989+
// TODO: Remove condition if "findex" is part of expand_T ?
990+
if (mode != WILD_EXPAND_FREE && mode != WILD_ALL && mode != WILD_ALL_KEEP)
991+
findex = 0;
989992

990993
if (mode == WILD_FREE) // only release file name
991994
return NULL;

src/testdir/test_cmdline.vim

+28-2
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,30 @@ func Test_cmdline_complete_various()
13361336
call assert_equal('"py3file', @:)
13371337
endfunc
13381338

1339+
" Test that expanding a pattern doesn't interfere with cmdline completion.
1340+
func Test_expand_during_cmdline_completion()
1341+
func ExpandStuff()
1342+
badd <script>:p:h/README.*
1343+
call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1344+
$bwipe
1345+
call assert_equal('README.txt', expand('README.*'))
1346+
call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1347+
endfunc
1348+
augroup test_CmdlineChanged
1349+
autocmd!
1350+
autocmd CmdlineChanged * call ExpandStuff()
1351+
augroup END
1352+
1353+
call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1354+
call assert_equal('"sign place', @:)
1355+
1356+
augroup test_CmdlineChanged
1357+
au!
1358+
augroup END
1359+
augroup! test_CmdlineChanged
1360+
delfunc ExpandStuff
1361+
endfunc
1362+
13391363
" Test for 'wildignorecase'
13401364
func Test_cmdline_wildignorecase()
13411365
CheckUnix
@@ -1675,6 +1699,7 @@ func Test_cmd_bang_E135()
16751699
augroup test_cmd_filter_E135
16761700
au!
16771701
augroup END
1702+
augroup! test_cmd_filter_E135
16781703
%bwipe!
16791704
endfunc
16801705

@@ -2134,7 +2159,7 @@ endfunc
21342159
func Test_cmd_map_cmdlineChanged()
21352160
let g:log = []
21362161
cnoremap <F1> l<Cmd><CR>s
2137-
augroup test
2162+
augroup test_CmdlineChanged
21382163
autocmd!
21392164
autocmd CmdlineChanged : let g:log += [getcmdline()]
21402165
augroup END
@@ -2150,9 +2175,10 @@ func Test_cmd_map_cmdlineChanged()
21502175

21512176
unlet g:log
21522177
cunmap <F1>
2153-
augroup test
2178+
augroup test_CmdlineChanged
21542179
autocmd!
21552180
augroup END
2181+
augroup! test_CmdlineChanged
21562182
endfunc
21572183

21582184
" Test for the 'suffixes' option

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1636,
698700
/**/
699701
1635,
700702
/**/

0 commit comments

Comments
 (0)