Skip to content

Commit 73d4e4c

Browse files
committed
patch 7.4.2274
Problem: Command line completion on "find **/filename" drops sub-directory. Solution: Handle this case separately. (Harm te Hennepe, closes #932, closes #939)
1 parent 3056735 commit 73d4e4c

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/misc1.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10514,18 +10514,34 @@ uniquefy_paths(garray_T *gap, char_u *pattern)
1051410514
/* Shorten the filename while maintaining its uniqueness */
1051510515
path_cutoff = get_path_cutoff(path, &path_ga);
1051610516

10517-
/* we start at the end of the path */
10518-
pathsep_p = path + len - 1;
10517+
/* Don't assume all files can be reached without path when search
10518+
* pattern starts with star star slash, so only remove path_cutoff
10519+
* when possible. */
10520+
if (pattern[0] == '*' && pattern[1] == '*'
10521+
&& vim_ispathsep_nocolon(pattern[2])
10522+
&& path_cutoff != NULL
10523+
&& vim_regexec(&regmatch, path_cutoff, (colnr_T)0)
10524+
&& is_unique(path_cutoff, gap, i))
10525+
{
10526+
sort_again = TRUE;
10527+
mch_memmove(path, path_cutoff, STRLEN(path_cutoff) + 1);
10528+
}
10529+
else
10530+
{
10531+
/* Here all files can be reached without path, so get shortest
10532+
* unique path. We start at the end of the path. */
10533+
pathsep_p = path + len - 1;
1051910534

10520-
while (find_previous_pathsep(path, &pathsep_p))
10521-
if (vim_regexec(&regmatch, pathsep_p + 1, (colnr_T)0)
10522-
&& is_unique(pathsep_p + 1, gap, i)
10523-
&& path_cutoff != NULL && pathsep_p + 1 >= path_cutoff)
10524-
{
10525-
sort_again = TRUE;
10526-
mch_memmove(path, pathsep_p + 1, STRLEN(pathsep_p));
10527-
break;
10528-
}
10535+
while (find_previous_pathsep(path, &pathsep_p))
10536+
if (vim_regexec(&regmatch, pathsep_p + 1, (colnr_T)0)
10537+
&& is_unique(pathsep_p + 1, gap, i)
10538+
&& path_cutoff != NULL && pathsep_p + 1 >= path_cutoff)
10539+
{
10540+
sort_again = TRUE;
10541+
mch_memmove(path, pathsep_p + 1, STRLEN(pathsep_p));
10542+
break;
10543+
}
10544+
}
1052910545

1053010546
if (mch_isFullName(path))
1053110547
{

src/testdir/test_cmdline.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ func Test_getcompletion()
180180

181181
call assert_fails('call getcompletion("", "burp")', 'E475:')
182182
endfunc
183+
184+
func Test_expand_star_star()
185+
call mkdir('a/b', 'p')
186+
call writefile(['asdfasdf'], 'a/b/fileXname')
187+
call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
188+
call assert_equal('find a/b/fileXname', getreg(':'))
189+
call delete('a', 'rf')
190+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2274,
766768
/**/
767769
2273,
768770
/**/

0 commit comments

Comments
 (0)